作者:GRcoder | 来源:互联网 | 2023-10-13 11:33
参考了这篇文章:https:segmentfault.comq1010000000473230后报错误:GettingError“Formsubmissioncanceledbec
参考了这篇文章:https://segmentfault.com/q/1010000000473230 后报错误:Getting Error “Form submission canceled because the form is not connected”
然后在:http://stackoverflow.com/questions/42053775/getting-error-form-submission-canceled-because-the-form-is-not-connected 找到了答案,增加了 $(document.body).append(form);后问题解决。
具体原理如下:
Details : According to the HTML standards, if the form is not associated browsing context(document), form submission will be aborted.
HTML SPEC see 4.10.21.3.2
In Chrome 56, this spec was applied.
var url = "__ROOT__/index.php/home/ApiInfo/register";
requestData = {'email': email,'pwd':pwd};
$.post(url, requestData, function (data) {
if(data != null){
alert(data);
}else{
var form = $("");
form.attr({"action":"__ROOT__/index.php/home/ApiInfo/sucess"});
$(document.body).append(form);
form.submit();
}
});
/////////////////////////////////////////
后来,用Form提交,AJAX验证,用另外的方法实现了:
var url = "__ROOT__/index.php/home/ApiInfo/isExist";
requestData = {'email': email};
var isOk = true;
$.ajax({
url:url,
type:'get',
data:requestData,
async: false,//关键操作,需要等到结果才执行后面操作
success:function(data){
alert(data);
isOk = false;
}
});
return isOk;