how to display jquery page(inside a div) using javascript?

故事扮演 提交于 2019-12-19 10:46:51

问题


here is my problem, i call this method and what it does is

post some data on server using jQuery, i want to display page using result i recieve from server

my page index.html

<div data-role="page" id="login">
    // other page content
            <div id="divrightButton">

            <!-- calling loginSubmit which calls loginPostData-->   
            <a class="bluebutton" href="#" onclick="loginSubmit(); return false;">Login</a>

            </div>
        </form>
</div>

<!--main page-->
<div data-role="page" id="mainMenu">

     Main menu
</div>

here is the piece of code from javascript, quick thing loginSubmit() calls loginPostData ,loginSubmit make a json object and pass it to loginPostData

function loginPostData(jsonRequest)
{
    $.post("http://localhost:8080/edserve/MobileServlet", 
            JSON.stringify( jsonRequest), 
            function(data) 
            {
                var obj = JSON.stringify(data);
                //var object = JSON.parse(json_text);
                //alert(obj);
                alert(obj);
                if(data.status=="success")
                {
                    //display main page
                    //$('#mainMenu').show(); <-- this does not give desired result
                }
                else
                {
                    if(data.message=="user not verified")
                    {
                        //display verification page
                    }   
                    if(data.message=="no user exist with this usname")
                    {
                        //set focus to username
                        $("#username").focus();
                    }   
                }   
        }, "json");
}

HOW TO SHOW MAIN MENU WHEN THERE IS SUCCESS, the entire code of html is in single file in different div's


use this code to redirect/display the particular div tag/element

$.mobile.changePage("#mainMenu",{allowSamePageTransition: true });

and also download following css file, its a must for transitioning between pages/div elements

jquery.mobile.transitions.css


回答1:


try this code

 $.mobile.changePage( "#mainMenu", { allowSamePageTransition: true }); 

and check this link

http://jquerymobile.com/test/docs/api/methods.html




回答2:


You can try using the jquery load function for this http://api.jquery.com/load/




回答3:


try this..

function loginPostData(jsonRequest)
    {
        $.post("http://localhost:8080/edserve/MobileServlet", 
                JSON.stringify( jsonRequest), 
                function(data) 
                {
                    var obj = JSON.stringify(data);
                    //var object = JSON.parse(json_text);
                    //alert(obj);
                    alert(obj);
                    if(data.status=="success")
                    {
                        $.mobile.changePage( "#mainMenu"); // main menu div id..
                    }
                    else
                    {
                        if(data.message=="user not verified")
                        {
                            //display verification page
                        }   
                        if(data.message=="no user exist with this usname")
                        {
                            //set focus to username
                            $("#username").focus();
                        }   
                    }   
            }, "json");
    }


来源:https://stackoverflow.com/questions/10828089/how-to-display-jquery-pageinside-a-div-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!