Jump to content

[SOLVED] AJAX work fine, how to stop form from submitting with regard to responseText?


satheshf12000

Recommended Posts

How would you make the JS mainFunction() stop? Bcos through AJAX, I call a PHP - MSSQL storedProc (executing the proc and php is not a problem here, proc is returning values i.e. 0 to 10 and I can get it with the responseText) and if it returns something I don't want, say if storedProc returns 0, I wound want to stop the mainFunction() from executing further. And the form should proceed only if the StoredProc returns 1 or any other values.

Issues:

[*]I have an alert message which doesn't even pop up if the mainFunction() doesn't have this statement at the end: return false;

[*]And the return false within the if ( responseMsg == 0 ) doesn't seem to stop the mainFunction

 

 

 

Can you guys pls help with this? Many thanks.. ;)

 

I have something like this:



/* JavaScript function */

function mainFunction() {



/*    a few form checking code and the AJAX request code goes here  */

    http.onreadystatechange = function() {
         
            if(http.readyState == 4 && http.status == 200) {

                var responseMsg = http.responseText;
                if ( responseMsg == 0 ) {
                      alert ("check submission return code was zero");
                      return false;
                } else if ( responseMsg == 1 ) {
                      alert ("check submission return code was one");
                      return false;
                }
            }

  }

}

 

And the HTML Code will look like this:



<input type="submit" value="Submit" name="preSubmissionFinished" onclick="return mainFunction()">

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.