我需要测试使用GET方法成功发送数据或等待1或2秒,但似乎setTimeOut函数不起作用。当我发出setTimeOut的警报时,它可以工作。
<form class="form-inline" method = "post" action="form1.php" id="formemail">
<div class="col-lg-6 col-md-7 col-sm-12 clearfix">
<div class="form-group desk-pull-left">
<label class="sr-only" for="NewsletterEmail">Email address</label>
<input type="email" size="60" class="form-control" id="NewsletterEmail" name="NewsletterEmail" placeholder="Enter email">
<span id="response">
</span>
</div>
</div>
<div class="col-lg-4 col-md-5 col-sm-7 clearfix">
<div class="form-group desk-pull-left">
<input type="submit" value="CONTINUE" class="desk-pull-right btn btn-primary btn-sm btn-continue">
</div>
</div>
</form>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$( document ).ready(function() {
$( "#formemail" ).submit(function( event ) {
if ( $( "#NewsletterEmail" ).val().length > 0 ) {
var email = $( "#NewsletterEmail" ).val();
var dataString = "pswd=NJGBUlS5y&url=proe.net&stamp=2014-11-17 21:40:00&ip=40.40.40.1&email=aaaaa@aaaa.com";
$.ajax({
type: "GET",
url: "https://www.acads.com/promox/livefeed.php",
data: dataString,
dataType: "script",
cache: false,
success: function(){
alert('successs');
},
error: function(){
alert('failed');
}
});
//$('body').append('<h1 ></h1>');
//console.log('hello');
setTimeout( function () {
$( "#formemail" ).submit();
}, 1000);
return;
}else{
alert( "Email field is Required!" );
event.preventDefault();
}
});
});
</script>
请问你有解决方案吗?
答案 0 :(得分:0)
在你的ajax中添加它。
async : false
答案 1 :(得分:0)
首先要了解开发人员控制台(the better one is in Chorme的强大功能,但类似的工具在Firefox和IE中)
其次,将error
回调添加到您的ajax调用中,而不仅仅是success
。只是为了选择不成功的请求。
最后,未定义超时调用中使用的form
变量。
答案 2 :(得分:0)
使用类似的东西:
setTimeout( function () {
$('#formId_searchform').submit();
}, 500);