Strategy to debug Javascript

Make sure you read the relevant API docs.

Use Chrome’s developer tools, Firebug, or IE’s, and Visual Studio debugger, they are awesome.

Use console.log and alert in code when necessary when tracing code is difficult.

Run JS scripts from JS console.

Don’t be afraid to trace through third party’s frameworks and libraries when necessary.

 

500.19 – Internal Server Error – The requested page cannot be accessed because the related configuration data for the page is invalid

Today I faced this error while trying to run a web application.

It turned out that it was occurred in a REST request to the server to retrieve a JSON file. I tried to solve this issue by first opening IIS and check the declared MIME types under the web application, then it complained that there is a duplicate entry in the web.config file.

It turned out that if the web.config file contains a declaration for the MIME type .json and under the application in IIS the MIME type is also declared, IIS will complain. I solved the issue by removing the MIME type declaration from the web.config file.

Ext JS component cannot display json data read from proxy

Not entirely sure why, but when using ajax proxies, specifying the URL is not enough, the data won’t be displayed on lists/panels.

A reader must also be defined in the proxy, otherwise the data will not be read correctly

proxy: {
type: ‘ajax’,
url: ‘data.json’,
reader:{
type:’json’,
rootProperty: ‘DATA’
}

}

Make sure that

  • the source data is working, test using Fiddler/POSTMan/etc
  • The model’s fields match the fields in json data, case-sensitive.
  • A reader is configured in the proxy
  • rootProperty is set correctly and match the json data, case-sensitive.

 

Differences between JSONP and JSON

Today I learned how Jsonp work, it basically makes use of HTML’s script tag to retrieve the JSON data from a different domain/origin.

The returned data is in the form of func({…}) where func is any function that can be defined before hand in the client. A script element will be added to the DOM that loads the data and execute it like any normal JavaScript file. Since there is no restriction imposed in the script element, it can load from any server in different domains/ports, unlike Ajax.

Basically it’s a hack. More details in the Stackoverflow answer: http://stackoverflow.com/a/2887218/5539403

Ext JS error [E] Layout run failed error

When I encountered this issue, it was because of the grid panel. According to this Stackoverflow answer http://stackoverflow.com/a/21740832/5539403 it is because the grid panel tries to shrink-wrap its content but there was no content at the time the layout run is executed.

I fixed it by setting the width of the grid panel somehow.