为什么我的JSONP请求给我Uncaught SyntaxError:意外的令牌< (少于)? [英] Why does my JSONP request give me Uncaught SyntaxError: Unexpected token < (less than)?
本文介绍了为什么我的JSONP请求给我Uncaught SyntaxError:意外的令牌< (少于)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的xmlfile
Following is my xmlfile
applica.luminoustec.net/file.xml
我需要通过本地主机的这个ajax调用来访问,所有这些都是跨域调用
I need to access with this ajax call from my local host, all about is cross domain call
我的AJAX代码
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: "http://applica.luminoustec.net/file.xml",
dataType: "jsonp",
success: function (data) {
console.log(data);
}
});
});
</script>
以下是错误
未捕获的SyntaxError:意外的令牌<
Uncaught SyntaxError: Unexpected token <
任何人都可以告诉我哪里有错误
can anyone tell where i am at fault
但没有成功请帮帮我
推荐答案
http://applica.luminoustec.net /file.xml
是XML。
dataType:jsonp,
告诉jQuery将其解析为JSONP。
dataType: "jsonp",
tells jQuery to parse it as JSONP.
XML不是JSONP。因此,它会出错。
XML is not JSONP. Thus, it errors.
要么:
- Change the URL to one which returns JSONP or
- Remove the
dataType
line and let jQuery detect it as XML (NB: This will probably require that you set up CORS support on the server).
这篇关于为什么我的JSONP请求给我Uncaught SyntaxError:意外的令牌< (少于)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文