Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 加载页面中的Phonegap导航ajax_Android_Cordova - Fatal编程技术网

Android 加载页面中的Phonegap导航ajax

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',

我正在尝试创建一个带有导航的索引,当单击该索引时,将通过ajax加载页面,而不是转到另一个html

这是我的javascipt:

<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;
                }
            }

        });