我有一个ASP.Net MVC3应用程序(不管是ASP.NET MVC、PHP还是RAILS,因为它最终提供的是编程HTML),它使用jquery,在所有移动浏览器中都工作得很好。我的下一步是使用Phonegap创建一个本地ios应用程序。
我的猜测是,我所要做的就是在我放在Phonegap中的html页面中,我将连接到页面加载事件,并从远程服务器动态加载MVC视图的内容。
但我正在寻找一些例子,如果其他人做了类似的事情。
-Thanks预置尼克
更新:I能够通过编写下面的index.html页面来完成这一任务。希望它能帮到别人。
仍然存在问题,尽管:但是在完成了this...as之后,您可能会注意到,我正在通过http://IP:8081 URL请求ASP.NET MVC页面。这很好,它加载我的页面too...but --它不是jquery格式化的。所以,如果有人能帮我,那就太好了。
解释:因为,ajax.responseText
包含从<!DOCTYPE html>
标记开始的整个<!DOCTYPE html>
.我认为很明显,我最后在我的<div data-role="page" id="home">
标记中插入了整个HTML页面,这显然是错误的,但我还没有一个解决方案:
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Ajax Sample</title>
<meta name="viewport" content="width=device-width,initial-scale=1, target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript">
function onDeviceReady() {
var ajax = new XMLHttpRequest();
ajax.open("GET", "http://192.168.2.30:8081/", true);
ajax.send();
ajax.onreadystatechange = function () {
alert(ajax.status);
if (ajax.readyState == 4 && (ajax.status == 200 || ajax.status == 0)) {
document.getElementById('home').innerHTML = ajax.responseText;
}
}
}
$(document).bind("mobileinit", function () {
alert('mobileinit');
// Make your jQuery Mobile framework configuration changes here!
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});
document.addEventListener("deviceready", onDeviceReady, false);
</script>
</head>
<body>
<div data-role="page" id="home">
</div>
<div data-role="page" id="search">
</div>
<div data-role="page" id="recent">
</div>
</body>
</html>
发布于 2012-05-23 23:37:09
为什么不使用jQuery助手从远程服务器加载页面。
$(document).bind("mobileinit", function () {
alert('mobileinit');
// Make your jQuery Mobile framework configuration changes here!
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$("#home").load('http://192.168.2.30:8081/ #targetContent');
});
加载方法可以发出请求并用ajax请求的结果替换选择器的内容。它还允许您在URL之后提供一个选择器,该选择器将针对要加载到原始匹配选择器中的远程服务器中的特定内容。
发布于 2012-05-07 01:39:09
据我所知,从广义上讲,PhoneGap有两个选项(我还没有亲自尝试过)。(现在我正在了解它们):
https://stackoverflow.com/questions/10465242
复制相似问题