views:

1423

answers:

2

I am using jquery to make an $.ajax() call to a REST web service. Based on the documentation I found, I need to use jsonp as the datatype in order to make this cross domain call (an XML document is what is actually returned). When running my code, however, I receive the error "XML cannot be the whole program".

Does anyone know what this error means and how to fix it (if at all)? Google searches have not provided much information and the other stack overflow post on this subject was not helpful to me either.

If you have additional questions, please let me know.

+1  A: 

Looks to me like you included a *.js file in your web app that contains <script></script> around the code...which is not needed. Those tags are making your code look like one big XML document to the parser.

Justin Niessner
I apologize if I am not getting this, but can you clarify your answer a bit? I don't think I understand what you mean by the js include being contained around the code.Thanks.
cmessier
here's my code:<html> <head> <title>JavaScript Practice</title> <script language="javascript" src="jquery-1.3.2.min"></script> <script language="javascript" src="scripts.js"></script> </head> <body> <a href="#" onclick="returnDisplay();">Click to Test</a> <div id="results"></div> </body></html>my scripts.js file does not contain any <script> tags.
cmessier
Can you post the relevant piece of your script.js file so we have an idea of what's going on there?
Justin Niessner
+1  A: 

If you need to return XML over a connection that requires JSON, you will have to wrap your xml. So, for example, if your document looks like this:

<magic8ball>
   <outcome_looks_doubtful/>
</magic8ball>

Then you will need to do something like this:

{"value": "<magic8ball>
    </outcome_looks_doubtful/>
</magic8ball"}

Then you are passing around JSON, like your jsonp datatype requires. All you have to do is extract your xml, and you're off and running.

jcdyer
+1, this is how you have to handle XML via JSONP.
jvenema