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()">

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.