我想从我的jQuery手机网站的JavaScript文件中检索信息。 Ajax默认启用,但当我尝试xmlHttpRequest.send()时,responseText是页面的源代码而不是json结构。 initialize()函数在pageinit上运行,所以我的想法是它被调用的json应该存在。另外,initialize()可以在网站的非移动版本上正常工作,所以我认为它与JQM处理Ajax请求的方式有关。预先感谢您的帮助。jQuery Mobile ajax请求
<!DOCTYPE html>
<html>
<head>
var xmlHttpRequest;
var json;
<script type="text/javascript">
function initialize()
{
xmlHttpRequest = (window.XMLHttpRequest) ? new XMLHttpRequest() :
new ActiveXObject("Msxml2.XMLHTTP");
if (xmlHttpRequest == null)
return;
xmlHttpRequest.open("GET", "pick.js", false);
xmlHttpRequest.send();
json = eval('('+ xmlHttpRequest.responseText +')');
}
</script>
......
</head>
<body>
<div data-role="page" id="map-page">
<script type="text/javascript">
$('#map-page').live('pageinit',function(){
initialize();
});
</script>
.....
</div>
</body>
</html>
您可以尝试使用招看交通是什么样子。 – Pete
只是要清楚 - 你试图动态获取脚本,然后在页面上执行它,对吧? –
这是正确的。 javascript在服务器上生成并包含json。我想要检索在浏览器中进行处理。 – petfreshman