jQuery中$.ajax()的get 方法

来源:互联网 发布:在英国怎么淘宝购物 编辑:程序博客网 时间:2024/05/16 12:25

这两天在搞跨域的问题,新手一个,就写写自己都遇到什么问题,总结一下吧。

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后面进行传参。

逻辑问题,基础知识欠缺。