Android jQuery Mobile show()和hide()Don';我不能在安卓系统中工作

Android jQuery Mobile show()和hide()Don';我不能在安卓系统中工作,android,jquery,show-hide,Android,Jquery,Show Hide,我试图在我调用ajax获取信息时显示一条“请稍候…”消息。基本上,用户输入他们的搜索词,点击搜索,我想在页面进行ajax调用时显示“请稍候…”,然后在调用完成后将其隐藏 我的jsp页面上有一个div,如下所示: <div id="modalWindow">Please Wait...</div> jQuery('#modalWindow').css({ 'text-align' : 'center', 'font-size' : '20px' }).hi

我试图在我调用ajax获取信息时显示一条“请稍候…”消息。基本上,用户输入他们的搜索词,点击搜索,我想在页面进行ajax调用时显示“请稍候…”,然后在调用完成后将其隐藏

我的jsp页面上有一个div,如下所示:

<div id="modalWindow">Please Wait...</div>
jQuery('#modalWindow').css({
    'text-align' : 'center',
    'font-size' : '20px'
}).hide();  //this is called when the page initially loads

jQuery('#modalWindow').show();    //I call this in the function that does the Ajax call

jQuery('#modalWindow').hide();    //I call this once the Ajax is done.
这是我的整个Ajax调用:

jQuery.ajax(
{
    url : urlContext + "/getItems.html",
    data :
    {
        txtItemReference : txtItemReference
    },
    dataType : "json",
    cache : false,
    async : false,
    timeout : 100000,
    success : function(jsonResponse)
    {
        if ( jsonResponse instanceof Object)
        {
            if (jQuery.isEmptyObject(jsonResponse))
            {
                createLocationDisplayPanel(false);
                createSimilarItemsPanel(false);
            }
            else if (jsonResponse['Locations'] != undefined)
            {
                responseArray = new Array();
                arrayStart = 0;
                intPage = 1;

                if (jsonResponse['Locations'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Locations'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                else
                {
                    responseArray = new Array();

                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                createLocationDisplayPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            else
            {
                if (jsonResponse['Items'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Items'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                else
                {
                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                createSimilarItemsPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            if (callback != undefined)
            {
                callback();
            }
        }
        else
        {
            alertLogout(document.URL);
        }
    },
    error : function(jsonResponse)
    {
        if (jsonResponse.hasOwnProperty('ERROR'))
        {
            alertError("There was no response from the server.");
        }
    }
});
jQuery.ajax(
{
    url : urlContext + "/getItems.html",
    data :
    {
        txtItemReference : txtItemReference
    },
    dataType : "json",
    cache : false,
    async : true,   //was false before
    timeout : 100000,
    success : function(jsonResponse)
    {
        if ( jsonResponse instanceof Object)
        {
            if (jQuery.isEmptyObject(jsonResponse))
            {
                createLocationDisplayPanel(false);
                createSimilarItemsPanel(false);
            }
            else if (jsonResponse['Locations'] != undefined)
            {
                responseArray = new Array();
                arrayStart = 0;
                intPage = 1;

                if (jsonResponse['Locations'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Locations'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                else
                {
                    responseArray = new Array();

                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                createLocationDisplayPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            else
            {
                if (jsonResponse['Items'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Items'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                else
                {
                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                createSimilarItemsPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            if (callback != undefined)
            {
                callback();
            }
        }
        else
        {
            alertLogout(document.URL);
        }
    },
    error : function(jsonResponse)
    {
        if (jsonResponse.hasOwnProperty('ERROR'))
        {
            alertError("There was no response from the server.");
        }
    }
});
jQuery.ajax(
{
url:urlContext+“/getItems.html”,
数据:
{
txtItemReference:txtItemReference
},
数据类型:“json”,
cache:false,
async:false,
超时:100000,
成功:函数(jsonResponse)
{
if(对象的jsonResponse实例)
{
if(jQuery.isEmptyObject(jsonResponse))
{
createLocationDisplayPanel(假);
createSimilarItemsPanel(假);
}
else if(jsonResponse['Locations']!=未定义)
{
responseArray=新数组();
arrayStart=0;
intPage=1;

if(jsonResponse['Locations'].length是否检查了jQuery是否在该点加载?请在脚本之前编写此代码

if (typeof jQuery == 'undefined') {  
    alert('jQuery is not loaded'); 
}

您可能需要组合脚本或找到一种方法来确保按照所需顺序加载脚本。

我发现问题在于Ajax调用的async属性:

jQuery.ajax(
{
    url : urlContext + "/getItems.html",
    data :
    {
        txtItemReference : txtItemReference
    },
    dataType : "json",
    cache : false,
    async : false,
    timeout : 100000,
    success : function(jsonResponse)
    {
        if ( jsonResponse instanceof Object)
        {
            if (jQuery.isEmptyObject(jsonResponse))
            {
                createLocationDisplayPanel(false);
                createSimilarItemsPanel(false);
            }
            else if (jsonResponse['Locations'] != undefined)
            {
                responseArray = new Array();
                arrayStart = 0;
                intPage = 1;

                if (jsonResponse['Locations'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Locations'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                else
                {
                    responseArray = new Array();

                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                createLocationDisplayPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            else
            {
                if (jsonResponse['Items'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Items'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                else
                {
                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                createSimilarItemsPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            if (callback != undefined)
            {
                callback();
            }
        }
        else
        {
            alertLogout(document.URL);
        }
    },
    error : function(jsonResponse)
    {
        if (jsonResponse.hasOwnProperty('ERROR'))
        {
            alertError("There was no response from the server.");
        }
    }
});
jQuery.ajax(
{
    url : urlContext + "/getItems.html",
    data :
    {
        txtItemReference : txtItemReference
    },
    dataType : "json",
    cache : false,
    async : true,   //was false before
    timeout : 100000,
    success : function(jsonResponse)
    {
        if ( jsonResponse instanceof Object)
        {
            if (jQuery.isEmptyObject(jsonResponse))
            {
                createLocationDisplayPanel(false);
                createSimilarItemsPanel(false);
            }
            else if (jsonResponse['Locations'] != undefined)
            {
                responseArray = new Array();
                arrayStart = 0;
                intPage = 1;

                if (jsonResponse['Locations'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Locations'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                else
                {
                    responseArray = new Array();

                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Locations'][x];
                    }
                }

                createLocationDisplayPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            else
            {
                if (jsonResponse['Items'].length <= 20)
                {
                    for (var x = arrayStart; x < jsonResponse['Items'].length; x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                else
                {
                    for (var x = arrayStart; x < (20 * intPage); x++)
                    {
                        responseArray[x] = jsonResponse['Items'][x];
                    }
                }

                createSimilarItemsPanel(jsonResponse, responseArray, txtItemReference, urlContext, callback);
            }
            if (callback != undefined)
            {
                callback();
            }
        }
        else
        {
            alertLogout(document.URL);
        }
    },
    error : function(jsonResponse)
    {
        if (jsonResponse.hasOwnProperty('ERROR'))
        {
            alertError("There was no response from the server.");
        }
    }
});
jQuery.ajax(
{
url:urlContext+“/getItems.html”,
数据:
{
txtItemReference:txtItemReference
},
数据类型:“json”,
cache:false,
async:true,//以前为false
超时:100000,
成功:函数(jsonResponse)
{
if(对象的jsonResponse实例)
{
if(jQuery.isEmptyObject(jsonResponse))
{
createLocationDisplayPanel(假);
createSimilarItemsPanel(假);
}
else if(jsonResponse['Locations']!=未定义)
{
responseArray=新数组();
arrayStart=0;
intPage=1;

if(jsonResponse['Locations'].length我测试了这个。我没有得到那个消息,所以实际上已经加载了jQuery。试试:alert(jQuery('#modalWindow').length);看看选择器是否失败。它应该是1。事实上,Android中不会发生常规的简单更改。我试着将输入框的值更改为“请稍候…”通过执行
jQuery('input#txtItemReference').val(“请稍候…”)
它仍然不起作用。在Firefox中起作用,在Android中不起作用…它返回1,所以它就在那里。你能提供你的Ajax调用吗?也许这是一个同步问题?