2011-05-06 90 views
1

我的问题是 - 当我直接进入这个特定的页面(newUserForm.jsp)时,我可以使用这个mehod点击按钮。但是当我在其他页面导航(http://localhost:8081/home.jsp#/newUserForm.jsp)后浏览此页面时,点击不会做任何事情 - 不在屏幕上显示名称。 (newUserForm.jsp :)jquery mobile与ajax问题

<!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> 

是否认为Ajax的电话吗?我在谷歌旅行时发现了这段代码...

谢谢。

+0

你没有实际使用jQuery做AJAX调用不能点击。您使用Internet Explorer的ActiveX或兼容浏览器的“XMLHttpRequest”。 – BoffinbraiN 2011-05-06 12:39:32

+1

此外,您不应该尝试使用ActiveX控制器,我们现在不再处于石器时代。 – Esko 2011-05-06 12:43:12

+0

感谢您的回答, – Hila 2011-05-06 12:56:22

回答

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

jQuery Mobile的使用V单击,