JQuery AJAX没有't获得成功回调功能
JQuery AJAX doesn't get to success call back function
这是我的jQuery Ajax代码
$(document).ready(function() {
$("#submitService").click(function(){
alert("Before ajax");
$.ajax({
type: "GET",
url: "http://api.openweathermap.org/data/2.5/weather?q=London,uk",
headers: {"accept": "application/json"},
success: function (dataItem) {
alert("Success..");
},
complete: function (dataItem) {
alert("Completed");
},
error: function (dataItem) {
alert("Error in making engine call."+dataItem);
}
});
alert("After ajax");
}); //click()
});
当我的按钮被点击时,它进入[完成]和[错误]回调方法,但不是"成功"回调方法。我如何才能看到错误是什么?
我试图歪曲同样的陈述,得到了有效的回应:
curl "http://api.openweathermap.org/data/2.5/weather?q=London,uk" -H "accept: application/json"
我使用的是jQuery 1.7.2
<script type="text/javascript" src='<spring:url value="/resources/jquery/js/jquery-1.7.2.min.js"/>'></script>
在FireBug中,它显示了200 OK的请求,但没有响应体。但当我通过卷曲来做时,我看到了反应体。
可能是什么问题?感谢
我想,这是URL编码问题。用编码%2C
替换逗号,
url: "http://api.openweathermap.org/data/2.5/weather?q=London%2Cuk"
取消点击事件
$("#submitService").click(function(e){
e.preventDeault();
...
让jQuery对URL 进行正确的编码
type: "GET",
url: "http://api.openweathermap.org/data/2.5/weather",
data: {q : "London,uk" },
希望该服务和您的浏览器都支持CORS,因为这是一个同源策略问题。
您注意到Api调用中没有Allow Access Origin吗?
我在chrome 上得到了这个
XMLHttpRequest无法加载http://api.openweathermap.org/data/2.5/weather?q=London,英国。不请求的上存在"Access Control Allow Origin"标头资源原点'http://jquery.com因此不允许访问。
我认为您有一个跨站点脚本问题。
将application/json更改为application/x-www-form-urlencoded
相关文章:
- 成功回调永远不会被JSONP请求调用
- 查询后websql成功回调无法访问变量
- 在$q服务中捕获拒绝而不触发成功回调
- 如何从ajax成功回调函数中读取javascript变量
- AJAX成功回调-执行javascript时出现问题
- 当使用命名函数作为jquery ajax成功回调时,我需要括号吗
- jQuery$.post可以在chrome、safari中工作,但不能在FF中工作(声明成功回调函数未定义)
- Yii ajaxbutton : 如何在成功回调函数中获取 $(this)
- 角承诺的“then”函数的成功回调的词汇范围是什么?
- 承诺中的成功回调不会发生$http
- Ajax成功回调仅适用于Chrome
- 将类方法绑定到类外绑定的事件处理程序内的AJAX成功回调
- 成功回调中的外部变量未正确更新
- 为什么jQuery成功回调有时有3个参数,有时只有1个
- 当通过Ajax成功回调更新可观察数组时,启用绑定中断
- 构建Ajax调用数组时,JQueryAjax成功回调不起作用
- JQuery AJAX没有't获得成功回调功能
- 如何访问作为参数发送到jquerypost的成功回调中的数据值
- 成功回调不是一个函数
- AngularJS$http.获取当时和成功回调之间的区别