data can be obtained by directly accessing a cross-domain request in the php method through url, but the result returned by the ajax request is empty.
php Code
$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)
});
has been tortured all day, and I have no idea why.