Search code examples
jqueryrestcross-domainjsonpasmx

ASMX cross-domain call (REST vs JSONP)


I am new to this stuff, and I have no idea what that is.. Searching from Google make me more confused.

I have .asmx web-service and .aspx web-page to consume the web-service. Now I want to change the web-service to do cross-domain call (using jQuery?) I found that there are two ways? ReST and JSONP? what is the difference between them?

As you can see, I am soooo confused.. any great article, explanation would be much appreciated!!

My web-service is simply returning a 'list' from database and I want to show that list as either XML or JSON.


Solution

  • To consume services across domains using ajax - you have the options JSONP or CORS

    JSONP is JSON with padding. The server basically returns a javascript. JSONP has some disadvantges like it is subject to XSS attacks, and second, it supports only HTTP GET requests

    example:

    Cross domain ajax request to a json file using JSONP

    For more details, refer What is JSONP all about?

    You can also use CORS for modern browsers, where the server adds additional headers like Access-Control-Allow-Origin to indicate which are the origin allowed to access the service. Refer CORS

    Also refer the wiki page for more techniques to circumvent same origin policy Ways to circumvent the same-origin policy

    REST is a way of sending and receiving data between client and server , and it will not help in cross domain calls AFAIK.