跨域访问怎么做呢,? 访问 json格式的数据, 求教,从昨天一直研究这个,也没弄出来
求教
<?php
$ary = array('result'=>0,'message'=>'跨域成功');
$json = json_encode($ary);
echo "$json;";
?>
$.getJSON("http://www.s94994.com/json.php",function(d){
//alert(1)
alert(d+'....40')
});
string strJson=GetWebContent("http://www.s94994.com/json.php",Encoding.UTF8);
private string GetWebContent(string Url, Encoding encoding)
{
string strResult = "";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//声明一个HttpWebRequest请求
request.Timeout = 90000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
//Encoding encoding = Encoding.UTF8;
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
streamReceive.Dispose();
streamReader.Dispose();
}
catch (Exception ex)
{ }
return strResult;
}
<script type="text/javascript" src="http://www.coding123.net/rardownload/20130106/20130106170832648.js"></script>
<script type="text/javascript" src="http://www.coding123.net/js/jquery.js"></script>
<script>
window.onload=function(){
$.getJSON("http://query.yahooapis.com/v1/public/yql", {
q: "select * from json where url="http://m.weather.com.cn/data/101010100.html"",
format: "json"
}, function(data) {
var $content = $("#content")
if (data.query.results) {
$content.text(JSON.stringify(data.query.results));
} else {
$content.text('no such code: ' + code);
}
});
}
</script>
<div id="content">
</div>
var tags =$$('head');
if(typeof(fun)=='function'){
if( document.all ){
s.onreadystatechange = function(){
if(/(complete
[解决办法]
loaded)/.test(this.readyState)){
fun(); s.onreadystatechange = null; s.parentNode.removeChild(s);
}};
}else{
s.onload = function(){ fun(); s.onload = null; s.parentNode.removeChild(s); };
}
}
tags[0].appendChild(s);
};
include("1.php","utf-8",function(){alert(_json);})