gruber
gruber

Reputation: 29759

ajax POSTS in jquery wanted to run sequentially

On my site after user clicks button I would like to check via ajax if userName is correct and email is Correct.

I would like to run 2 ajax POSTS. If first returns that user name is incorrect simply return false from javascript and alert (wrong userName). If userName is correct than check email (if there is already in database). If it is then alert (email already taken).

I ve got problem with sequentail execution of this code.

How can I acheive it ?

Here is code for my check function:

$.ajax({
     type: "POST",
     url: "WebService.asmx/CheckEmail",
     data: "{'Email': '" + $('#<%= tbEmail.ClientID %>').val() + "'}",
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     success: function (msg) {
       if (msg == false) {
          alert("email already taken");
       } else {
          proceede();
       }
     }
})

I would like to invoke similar function as domething like callback for this one.

Thanks for any help

Upvotes: 0

Views: 105

Answers (2)

Jignesh Rajput
Jignesh Rajput

Reputation: 3558

Set the async option to false, e.g.,

$.ajax({ async: false /*, your_other_ajax_options_here */ });

Reference: Ajax/jQuery.ajax

Upvotes: 1

Kemal Can Kara
Kemal Can Kara

Reputation: 416

Why you post twice? Just get name and email and send it to the server. Then write your own logic for control there. Then u return an answer with the message you want?

If you really do that for some reason u can return string value from the first result and u can check it with

msg=="1" 

then u can execute your second function. Please give more information if this doesnt help you.

Upvotes: 0

Related Questions