久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放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. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      ajax請(qǐng)求報(bào)錯(cuò),php如何開啟跨域請(qǐng)求

      本篇文章給大家介紹一下ajax請(qǐng)求報(bào)錯(cuò),php開啟跨域請(qǐng)求的方法。有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)大家有所幫助。

      ajax請(qǐng)求報(bào)錯(cuò),php如何開啟跨域請(qǐng)求

      在php文件頭部加入

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

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

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

      如果是php框架的話需要放在namespace后面,而不是前面,否則會(huì)報(bào)錯(cuò)

      *.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請(qǐng)求報(bào)錯(cuò),php如何開啟跨域請(qǐng)求

      推薦學(xué)習(xí):php視頻教程

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