首页 > Web开发 > 详细

ajax 跨域请求

时间:2016-11-16 15:12:35      阅读:109      评论:0      收藏:0      [点我收藏+]
<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

ajax 跨域请求

原文:http://www.cnblogs.com/zengdiao/p/6069059.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!