0

I need to test that the data are successfully send with GET method or wait 1 or 2 second, but it seems that the setTimeOut function doesn't work. And when I make an alert instate of setTimeOut it works.

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

Please can you have a solution for this?

Med Sassi
  • 1
  • 1
  • 1
    For `form.submit();` : `form` is defined somewhere? Probably not... – Magicprog.fr Nov 18 '14 at 12:37
  • i forget to define it, but even i change it by $('form') still not working.... – Med Sassi Nov 18 '14 at 12:54
  • Add alert (or console.log) to your setTimeout callback. Maybe it was called many times but you requests are hang in pending state. BTW as your code acts form _should_ be send infinite times. – Roman Bekkiev Nov 18 '14 at 14:22
  • Yeah, actually that URL fails on timeout after 1.3 min pending. And after that `error` callback will be called. Just take a look to 'network' tab in developer tools. – Roman Bekkiev Nov 18 '14 at 14:27

3 Answers3

0

Add this in your ajax.

async : false
vanarajcs
  • 968
  • 2
  • 7
  • 18
0

First of all learn the power of developers console (the better one is in Chorme but similar tools are in Firefox and in IE)

Second, add the error callback to your ajax call, not only success. Just to pick unsuccessful requests.

And finally the form variable used in timeout call is not defined.

Roman Bekkiev
  • 3,010
  • 1
  • 24
  • 31
0

Use something like this :

setTimeout( function () {

    $('#formId_searchform').submit();
}, 500);
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
kki3908050
  • 165
  • 2
  • 9