JQuery中ajax跨域问题
2015-02-12 16:28
260 查看
var url = "http://apis.juhe.cn/idcard/index?key=e0a6277420506b2816b82f7d7821976c&cardno="+$(this).val(); $.ajax(url, { dataType: "json", crossDomain: true, success: function(data) { alert(data) }, error:function(XMLHttpRequest, textStatus, errorThrown){ alert("1-"+XMLHttpRequest.status); alert("2-"+XMLHttpRequest.readyState); alert("3-"+textStatus); } });
在测试上面代码的时候,老报这个错误: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. 然而网上查了一下这是ajax的跨域问题。找了两小时的bug之后,后面才发现把dataType的属性值改成 jsonp就行了。
相关文章推荐
- jQuery中利用JSONP解决AJAX跨域问题
- 利用JSONP解决AJAX跨域问题的原理与jQuery解决方案
- ie-9 以下ajax无法跨域的问题。只要add:jQuery.support.cors=true;即可
- jquery处理ajax跨域问题方法(一)(转)
- jquery中的ajax处理跨域问题-之-----jsonp
- 使用JQUERY解决AJAX的跨域问题
- 夺命雷公狗jquery---62通过$.getJSON来解决Ajax跨域请求问题
- webstorm jquery ajax请求跨域问题解决
- 关于JQUERY的AJAX跨域问题
- jquery ajax springMVC 解决跨域问题
- 使用jsonp及jquery的$.ajax解决跨域问题
- 跨域请求jQuery的ajax jsonp使用常见问题解答
- jQuery中利用JSONP解决AJAX跨域问题
- jQuery中的Ajax实现跨域请求,完成同源策略问题
- 使用JQUERY解决AJAX的跨域问题
- 利用JSONP解决AJAX跨域问题的原理与jQuery解决方案
- 解决webservice用Ajax(jquery)传递客户端请求时ip跨域问题(异步域请求)
- JQuery中ajax跨域问题
- 用jQuery实现ajax总结以及跨域问题
- 关于试用jquery的jsonp实现ajax跨域请求数据的问题