jquery的ajax和jsonp的写法


交互 ajax jsonp
ajax跟之前一模一样
$(document).ready(function(){
    $.ajax({
        url:'get.php',
        type:'get', //或者写'post'
    timeout:"3000",
        cache:"false",
        data:{
            a:12,
            b:5
        },
        success:function(str){
            alert(str);
        },
        error:function(err){
            alert(err);
        }
    });
});
注意:向后台传一个json的写法
$.ajax({
url: URL+'/tasks/task',
type: 'PUT',
   chache:"false",

contentType: "application/json",
data: JSON.stringify({
data: {
"key":"value"
}
}),
dataType: "json",
success:function(str){
if(str.errcode==0){
//发送数据成功
}
},
error:function(err){
alert(err);
}
});

 
jsonp
$(document).ready(function(){
    $.ajax({
url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',
        dataType:'jsonp',
        jsonp:'cb',
        data:{
            wd:'XX.value'
        },
        success:function(result){
            alert(result.s);
        } ,
        error:function(err){alert(err)}
    });
}); 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM