Friday, 15 April 2011

javascript - jquery ajax call not returning as expected -


I'm sure that it jquery calls ajax why fail. Actually, I want to get certified and if there is certification success then do something.

I have come to know this but the answer seems to be summarized in order to use too much for me (believe that you already know how to apply the solution).

Function authentication () {$ .ajax ({// TODO:

Securely (SSL?) It type: ' POST ', url:' / clientAuthenticate.php ', data: {username: username, password: password}, ​​success: function (data) {if (data ===' true ') "returns" returns "user" Failed to log into the system. \ N Email request has been ignored. \ N \ n Error message: \ n "+ data;}}, error: function (jxaxhr, textstats, errorpruneration) {w C "user failed to enter system. Probable problem with server or connection.";}});

And I call it in this function:

  Function Effort Submit Request (EK) {var authReturn = authenticate (); if (authReturn == "true") {emailEvent (eKey);} and {Warning (authReturn);}}  

When it comes back, it always warns that authReturn is "undefined" I suspect that authReturn is not defined as defined That the authentication function is 'finished' before the AJAX call ...

But I'm not sure how to fix this problem

I suspect that I will return the return values Instead of making separate calls ... (in this example, calling the email event function directly in the AJAX success function), but it will make the authentication function unique ... and use it for authentication for other purposes Right in Will not.

You can use your code but a callback will be required.

  Function Authentication (OnSewas, Onfail) {$ .ajax ({// TODO: Send it securely (SSL?) Type: 'Post', URL: 'include / clientAuthenticate.php ', Data: {username: username, password: password}, ​​success: work (data) {onsuccess (data); // you should check that this is function}, error: function (jqXHR, textstats, error reporting) {Onfail (errorThrown);}}}; Function Effort Submit Request (A) {Authentication (Function (AJAXData) {Email Event ('Whatever You Want to Send')}}, Function (Error Message) {Warning (Wrong);}); }  

No comments:

Post a Comment