【发布时间】:2013-10-10 00:40:12
【问题描述】:
我收到此代码的错误,但它应该可以工作。我想向loginck.php 发送数据并获得服务器响应。有什么错误吗?
<link rel="stylesheet" href="css/jquery.mobile-1.3.0-beta.1.css" />
<link rel="stylesheet" href="css/jqm-docs.css"/>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jqm-docs.js"></script>
<script src="js/jquery.mobile-1.3.0-beta.1.js"></script>
HTML:
<div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
<form action="#" method="post" autocomplete="off">
<div style="padding:10px 20px;">
<h3>Please sign in</h3>
<label for="un" class="ui-hidden-accessible">Username:</label>
<input type="text" name="username" id="un" value="" placeholder="username" data-theme="a" />
<label for="pw" class="ui-hidden-accessible">Password:</label>
<input type="password" name="password" id="pw" value="" placeholder="password" data-theme="a" />
<button type="submit" name="submit" id="submit" value="submit-value" data-theme="b">Sign in</button>
</div>
</form>
</div>
$.ajax:
$(window).load(function(e){
$('#submit').bind('click', function(e) {
e.preventDefault();
$.ajax({
type : "POST",
url : "loginck.php",
crossDomain: true,
beforeSend : function() {$.mobile.loading('show')},
complete : function() {$.mobile.loading('hide')},
data : {username : 'subin', password : 'passwordx'},
dataType : 'json',
success : function(response) {
//console.error(JSON.stringify(response));
alert(response);
},
error : function() {
//console.error("error");
alert('Not working!');
}
});
});
});
【问题讨论】:
-
你的错误是什么?控制台日志中有什么内容?
-
我收到警报“不工作!”
-
可以直接从浏览器调用
loginck.php?username=subin&password=passwordx吗?你确定日志里什么都没有吗stackoverflow.com/questions/4743730/… -
是的,我可以调用 'loginck.php?username=subin&password=passwordx'。 thr 没有日志。
-
尝试使用 jqm 1.3.2 和 jq 1.9.1 另外,将
window.load替换为$(document).on('pageinit', function { ... });
标签: php ajax jquery jquery-mobile