ajax 跨域请求

<script type="text/javascript">
$.ajax({
    type:'get',
    url:"http://www.xxx.com/oep-new/index.php/cast/upcast/"+val,
    dataType:'jsonp',
    // async: false,
    //beforeSend:function(){
       //$('#cast_order').html(imgshow);
    //},
    success:function(data){
        alert(data)
    },
    error: function(xmlHttpRequest,error) {
        
    }
});
</script>

//注意:dataType:的存在,beforeSend是不会执行的。跨域必须get,不能post。跨域请求只能是异步请求设置async: false无效。

 

public function upcast($dotype=''){
    $callback = $_GET['callback'];
        // $results = array(1,2,3);
        // echo $callback . '(' . json_encode($results) . ')';
    echo $callback.'(1)'; //返回文本1
}

 

https://www.zhihu.com/question/19618769

http://bbs.csdn.net/topics/390732999

http://bbs.csdn.net/topics/350109002

posted @ 2016-11-16 12:35  蚂蚁羽  阅读(203)  评论(0编辑  收藏  举报