jquery跨域的请求

2017-08-02  本文已影响0人  xiaoaiai
<!DOCTYPE html>
<html>
<head>
    <title>jq 跨域</title>
</head>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
    $.ajax({
        type : "post",
        url : "http://cnyc.carking998.com/ajax.php",
        data:{title:'dadf'},
        dataType : "jsonp",
        jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(默认为:callback)
        jsonpCallback:"success_jsonpCallback",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名
        success : function(json){
            console.log(json[0].text);
            // alert('success');
        },
        error:function(){
            alert('fail');
        }
    });
})
</script>
<body>

</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读