开发者

jQuery mobile with ajax issue

When I go directly to this specific page (newUserForm.jsp) I can use this method when clicking the button. But when I arriving this page after navigating in other pages (http://localhost:8081/home.jsp#/newUserForm.jsp) the click is not doing anything- not displaying the name on the screen. (newUserForm.jsp:)

<!DOCTYPE html>
<html>
<head>
        <title>JQuery Mobile AJAX</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-    1.0a2.min.css" />
        <script src开发者_运维百科="http://code.jquery.com/jquery-1.4.4.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
</head>
<body>
<script>
     $(function()
        {
                $("#callAjax").click(function()
                {
                        var theName = $.trim($("#theName").val());
                        if(theName.length > 0)
                        {
                                $.ajax({
                                        type: "POST",
                                        url: "/callajax.jsp",
                                        data: ({name: theName}),
                                        cache: false,
                                        dataType: "text",
                                        success: onSuccess
                                });
                        }
                });
                $("#resultLog").ajaxError(function(event, request, settings, exception)
                {
                        $("#resultLog").html("Error Calling: " + settings.url     + "<br />HTPP Code: " + request.status);
                });
                function onSuccess(data)
                {
                        $("#resultLog").html("Result: " + data);
                }
        });
</script>
<div data-role="page" id="indexPage">
        <div data-role="header">
                <h1>JQuery Mobile</h1>
        </div>
        <div data-role="content">
                <div data-role="fieldcontain">
                        <label for="theName">Please enter your name:</label>
                        <input type="text" id="theName" name="theName" value="" />
                </div>
                <input id="callAjax" type="button" value="Call Ajax" />
                <div id="resultLog"></div>
        </div>
        <div data-role="footer">
                <h1>AJAX Demo</h1>
        </div>
</div>
</body>
</html>

Is it considered as ajax-call? I've found this code while travelling at Google...


$("#callAjax").bind('vclick',function(){...})

jQuery mobile uses vclick, not click

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜