久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      ajax請求報錯,php如何開啟跨域請求

      本篇文章給大家介紹一下ajax請求報錯,php開啟跨域請求的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有所幫助。

      ajax請求報錯,php如何開啟跨域請求

      在php文件頭部加入

      header(“Access-Control-Allow-Origin: *”);

      如果想設置只允許某個網(wǎng)站通過的話可以這樣設置

      header(“Access-Control-Allow-Origin: http://test.com”); // 允許test.com發(fā)起的跨域請求,其他的都不通過

      如果是php框架的話需要放在namespace后面,而不是前面,否則會報錯

      *.php

      <?php  	header('Access-Control-Allow-Origin: *'); 	$arr = [ 		array('id'=>1,'title'=>'one1'), 		array('id'=>2,'title'=>'one2'), 		array('id'=>3,'title'=>'one3'), 		array('id'=>4,'title'=>'one4'), 	];  	echo json_encode($arr);  ?>

      index.html

      <script type="text/javascript" src="jq.js"></script> <script type="text/javascript"> 	$.ajax({ 		type:'post', 		url: 'http://127.0.0.1/demo1/api.php', 		contentType: "application/x-www-form-urlencoded", 		dataType: 'json', 		success: function(res){ 			console.log(res) 		} 	}) </script>

      ajax請求報錯,php如何開啟跨域請求

      推薦學習:php視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號