good_moring_的博客通过本文主要向大家介绍了jquery ajax get,jquery ajax get请求,jquery的ajax方法,jquery中的ajax方法,jquery调用ajax的方法等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
这两天在搞跨域的问题,新手一个,就写写自己都遇到什么问题,总结一下吧。
1.用get方法来请求数据
$.ajax({
type: 'GET',
url:'http://write.blog.csdn.net',
dataType: 'json',
success: function( result ) {
console.log(result.data.order_list);
orderList.lists = result.data.order_list;
}
});
所遇到的问题:
url的跨域问题,无法访问,最后通过服务器转发解决,但post方法似乎不能用服务器转发,一直报错,求指导~
2.用get方法向服务器返回数据
$.ajax({
type:'GET',
url: 'http://write.blog.csdn.net',
dataType: 'json',
data: {
key: '1e9e532fcf27238d4364c2ad36',
pre_order_id: orderList.lists[index].pre_order_id,
store_address: updata
},
success:function(result) {
console.log(result)
if(result.state === 'success') {orderList.lists[index].store_address = updata;
alert("修改成功")
}else{
alert("修改失败")
}
},
error:function() {
console.log()
alert('服务器走丢了')
}
})
所犯的错:
success有返回值之后并没有去测试,判断返回值是否正确,就执行了修改语句;
data里面的参数也可以通过键值对的方式添加到url后面进行传参。
逻辑问题,基础知识欠缺。