XML cannot be the whole program

佐手、 提交于 2019-12-13 14:18:08

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1771521/xml-cannot-be-the-whole-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!