Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-domain Ajax call gets no element found Location: moz-nullprincipal

I am trying to invoke a cross-domain web service through jquery call $.ajax() The service returns

<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">1.4248</double>

If I specify dataType xml (or not specifying anything - jquery guesses correctly), I am getting XML Parsing Error: no element found Location: moz-nullprincipal:{4030734c-b902-4251-9067-1d1b5b15fc72} Line Number 1, Column 1: error (looks like nothing is coming back from the service). However, if I specify dataType jsonp or script - I can see in firebug that everything is coming back correctly; however jquery apparently tries to eval the results and gives me corresponding error (missing semicolon or similar).

Is there a way in jQuery to enable cross-domain call and not evaluate it?

Notes:

  1. I know that the fallback option is to call a program on my server that will invoke the web service and return the result to the browser;
  2. I did specify crossDomain: true. It doesn't seem to make any difference.
  3. "error" function does get invoked. But instead of original value "data" contains "parseerror".
like image 431
Felix Avatar asked Aug 13 '11 23:08

Felix


1 Answers

Cross domain ajax is only allowed for JSONP, not XML

In JQuery 1.5 they added the crossDomain:true parameter which simply appends a ?callback=> value to the url. If you set that parameter, you must also set dataType:'json'. The cross-domain URL must also support JSONP and be serving up your expected data as such.

like image 188
AlienWebguy Avatar answered Nov 07 '22 22:11

AlienWebguy