Skip to content Skip to sidebar Skip to footer

Understanding Cross Domain Xhr And Xml Data

I have been working with JavaScript and AJAX for quite sometime, I would like to understand how Cross Domain XHR really work and how JQuery handles it, for some reason I have never

Solution 1:

Q) Is it possible to use XML data instead of JSON in similar way?

no because JSONP is not json ,it is javascript.The client is requiring a a script from the server , that get executed on the client. "JSONP" is a trick that uses a script tag to get a javascript object. You could , send a XML in a string though in a javascript object.

Q) The only way I can think of doing this otherwise is proxying the data through same domain. Is this understanding correct?

or make the server support CORS

http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

My point is , if the domain doesnt allow X-origin requests by defaults coming from client scripts , you cant do anything about it. Some browsers may allow it , but it is not a default behavior.in that case The only option is a proxy on the same domain.

Solution 2:

@adeneo answered the question but in comment. So my understanding about JSONP was fundamentally flawed. When JSONP request is made, it is not an XHR request. Rather, caveat is to insert script tag dynamically and fetch the JSON. So even though, the call looks like XHR(at least IMO JQuery), it is not. XMLHttpRequest object is not used at all.

This question has already been answered What is JSONP all about? but I somehow missed it before. Another good resource explaining Cross Domain request is at devlog

Rest of the issues I have raised become redundant!

Post a Comment for "Understanding Cross Domain Xhr And Xml Data"