Android 加载页面中的Phonegap导航ajax
我正在尝试创建一个带有导航的索引,当单击该索引时,将通过ajax加载页面,而不是转到另一个html 这是我的javascipt:Android 加载页面中的Phonegap导航ajax,android,cordova,Android,Cordova,我正在尝试创建一个带有导航的索引,当单击该索引时,将通过ajax加载页面,而不是转到另一个html 这是我的javascipt: <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> function getPage(){ $.ajax({ type: 'post',
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
function getPage(){
$.ajax({
type: 'post',
url: 'places.html',
success: function(html)
{
$("#response").fadeIn("slow");
$("#response").html(html);
}
});
return false;
}
</script>
美元.ajax位于哪一行您必须等待设备准备好进行ajax调用
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
function getPage(){
$.ajax({
type: 'post',
url: 'places.html',
success: function(html)
{
$("#response").fadeIn("slow");
$("#response").html(html);
}
});
return false;
}
}
ajax工作正常,最后需要完整的文件地址并将其放入documentready中
$.ajax({
type: 'post',
url: 'file:///android_asset/www/.html/places.html',
success: function(html)
{
$("#response").fadeIn("slow");
$("#response").html(html);
}
});
我发现的另一种方法是
$("#getProfile").click(function() {
var ajax = new XMLHttpRequest();
ajax.open("GET","file:///android_asset/www/places.html",true);
ajax.send();
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && (ajax.status==200||ajax.status==0)){
var theHTML = ajax.responseText;
document.getElementById('response').innerHTML = theHTML;
}
}
});
感谢您的帮助,Malek您的phonegap项目中的文件路径正确吗?确定修复了$not defined的问题,但我得到了一个02-14 09:56:32.180:E/Web控制台(20736):未捕获引用错误:getPage未在file:///android_asset/www/index.html:127,为什么会发生这种情况?
$.ajax({
type: 'post',
url: 'file:///android_asset/www/.html/places.html',
success: function(html)
{
$("#response").fadeIn("slow");
$("#response").html(html);
}
});
$("#getProfile").click(function() {
var ajax = new XMLHttpRequest();
ajax.open("GET","file:///android_asset/www/places.html",true);
ajax.send();
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && (ajax.status==200||ajax.status==0)){
var theHTML = ajax.responseText;
document.getElementById('response').innerHTML = theHTML;
}
}
});