通过url直接访问php方法里一个跨域请求可以得到数据,但是用ajax请求返回的结果为空。
php 代码
$host = "xxx.xxxx.cn/Home/Index/index";
// $header[] = "Content-type: text/xml;charset=UTF-8";
// $ch = curl_init();
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($host)); //参数
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT,5);
$arra = curl_exec($ch);
curl_close($ch);
$arra = json_decode($arra,true);
foreach ($recommend as $value) {
foreach ($arra as $v) {
if ($value['id'] == $v['shop_id']) {
$rmd[]=array_merge_recursive($value,$v);
}
}
}
if (count($rmd) < count($recommend)) {
$diff = array_diff_key($recommend,$rmd);
foreach ($diff as $val) {
$pageview['pageview'] = 0;
$aa[] = array_merge_recursive($value,$pageview);
}
}
$recommends =array_merge_recursive($aa,$rmd);
// var_dump($recommends);
return $this->ajaxReturn($recommends , 1, 1);
ajax$.ajax({
type: "POST",
dataType: "json",
url: "{:U('Shop/Site/GetRecommend')}",
data: null,
success: function(result) {
//这里得到的结果为空
console.log(result)
});
被折磨一天了,完全不清楚是什么原因。
- 5 回答
- 0 关注
- 1146 浏览
添加回答
举报
0/150
提交
取消