View Full Version : synchronous Ajax-call?

15 Sep 2009, 10:05 AM
I'm very new to ext, so maybe u can give me a hint. I have to modify an existing webform and for that I have to test some entries. Therefor there are some requests in the background.
It wouldn't be any problem to do the checks on the server-side, but I didn't get it on the client-side. Can anyone of u tell me, why I cannot set any global var after the Ajax-requests and return it to the form?

<FORM METHOD="POST" ACTION="..." onsubmit="return validateForm();">

var jsonResponse;

function validateForm() {
var r;
url: '...l',
disableCaching: true,
method: "post",
params: {
action: 'accountNr',
accountNr: 'abc123'
success: function (response, options) {
r = doSomeMoreChecks();
failure: function (response, options) {
r = false;

return r;

function setResponse(res) {
jsonResponse = res;

function doSomeMoreChecks(){
//something with jsonResponse-data
return true/false

thanx ;-)

24 Sep 2009, 9:33 AM
Ajax is not synchronous. you will need to return false in validateForm, then set the proper window.location in the success ofr failure of the ajax submission.

Mike Robinson
24 Sep 2009, 9:48 AM
AJAX = "Asynchronous JavaScript With"

When you make a request, the script does not wait for it to complete.

Instead, you specify handlers which will be (eventually... maybe... unless a meteor hits the server-room at the wrong instant) called when the request "succeeds" or "fails."

Again: you do not know when the handler will be called.

Wrap your mind around this. Don't worry if it takes a while. :-/ You're among friends!