我正在尝试使用dojo.xhrPost
. 下面的代码在 chrome 中运行良好,但在 Firefox 中根本不起作用。当我说它不起作用时,我看到该页面再次重新加载并且没有任何反应。我尝试使用dojo.stopEvent(event);
但似乎无法在 Firefox 中使用。
你能建议我什么可能是我的错误。我觉得问题更多在于表单而不是 xhrPost。
HTML 如下所示:
<div data-dojo-type="dijit/form/Form" data-dojo-id="myform" id="loginform"
encType="multipart/form-data" action="" method="post">
<script type="dojo/method" data-dojo-event="onSubmit">
if(this.validate()){
senddata(); //calling the javascript function
}else{
alert('Form contains invalid data. Please correct first');
return false;
}
return true;
</script>
<table cellspacing="10">
<tr>
<td><label for="name">Username:</label></td>
<td><input type="text" id="username" name="username"
required="true" placeholder="Your UserName" data-dojo-
type="dijit.form.ValidationTextBox"/></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" id="password" name="password"
required="true" placeholder="Your Password"
data-dojotype="dijit.form.ValidationTextBox"/></td>
</tr>
</table>
<div id="response" style="float: right"></div>
<button data-dojo-type="dijit.form.Button" type="submit" name="submitButton"
value="Submit" style="float: right;">Submit</button>
</div>
我的Javascript代码如下:
function senddata(){
dojo.stopEvent(event);
obj = {};
obj.user_name =dijit.byId("username").get("value");
obj.password =dijit.byId("password").get("value");
var xhrArgs = {
url: "./script/php/validatelogin.php",
postData: obj,
handleAs: "json",
load: function(data){
//alert('success');
if(data.success==true){
window.location = data.message;
dojo.byId("response").innerHTML = "Form posted.";
}else{
dojo.byId("response").innerHTML = "login Failed";
}
},
error: function(error){
console.log("error occured!!!");
dojo.byId("response").innerHTML = "Failed to Post the Form..";
}
};
//alert('starting');
var deferred = dojo.xhrPost(xhrArgs);
//alert('done');
return false;
}