您现在的位置是:首页 > 电脑技术查询 > web开发

jquery获取页面信息失败?解决办法

编辑:chaxungu时间:2022-10-02 23:16:10分类:web开发

jquery获取页面信息失败?
用jquery获取远程页面信息。
以下是范例代码:
JScript code $.ajax({ type: "GET", url: "http://www.baidu.com", dataType:"html", beforeSend: function(XMLHttpRequest){ $("#area").html("sending request..."); }, success: function(data, textStatus){ $("#ajax").html(data); }, complete: function(XMLHttpRequest, textStatus){ $("#area").html("complete request..."); }, error: function(){ $("#area").html("error occurs..."); } });
HTML code<div id="ajax"><div id="area"></div>
在运行时什么也不显示,那就是说请求失败了,请问这是为什么啊?
如果这样的写法是错误的,请问正确的写法是什么啊?(例如我想获取"www.baidu.com"的title)
感谢!

------解决方案--------------------
探讨

引用:

这是跨域请求,网站不允许

那么我们平时要调用别人给出的api(xml格式的和json数据格式的),应该怎么调用啊?