007 - 利用PHP解决跨域

xiaoxiao2021-02-28  104

1、利用后台文件去请求跨域连接,来达到实现跨域的目的

$().ready(function() { createCity(); $("#city").bind('change', function() { //城市代码 var code = this.value; var data = { code : code }; $.post('create.php', data, function(msg) { $('#result').append('城市:'+msg.weatherinfo.city+'<br>'); $('#result').append('日期:'+msg.weatherinfo.date_y+'<br>'); $('#result').append('温度:'+msg.weatherinfo.temp1+'<br>'); }, 'json'); }); }); function createCity() { $.post('createCity.php', function(msg) { $(msg).each(function(i, item) { var op = new Option(item.name, item.code); $("#city")[0].options.add(op); }); }, 'json'); } <?php $code = $_POST['code']; $file = "http://m.weather.com.cn/atad/" . $code . "html"; $content = file_get_contents( $file ); echo $content;
转载请注明原文地址: https://www.6miu.com/read-37267.html

最新回复(0)