I have a really strange problem with jquery. I'm trying to send something to the server and get data back. I have success function and error function. when the jquery ajax is invoked the first time - the error function gets called. the second time (on the same page) - it's successful. I have not idea why is that. here is my javascript code:
$.ajax ({
type : 'POST',
url: "/checkout/test",
context: document.body,
success: function(data){
alert (data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus)
}
});
on the server side, it's just a php page returning "testing" string without any html.
this is the content of XMLHttpRequest when the error occures:
readyState: 0;
setRequestHeader: function (a, b) {
if (!s) {
var c = a.toLowerCase();
a = m[c] = m[c] || a, l[a] = b;
}
return this;
};
getAllResponseHeaders: function () {
return s === 2 ? n : null;
};
getResponseHeader: function (a) {
var c;
if (s === 2) {
if (!o) {
o = {};
while ((c = bD.exec(n))) {
o[c[1].toLowerCase()] = c[2];
}
}
c = o[a.toLowerCase()];
}
return c === b ? null : c;
};
overrideMimeType: function (a) {
s || (d.mimeType = a);
return this;
};
abort: function (a) {
a = a || "abort", p && p.abort(a), w(0, a);
return this;
};
pipe: function (a, c) {
return f.Deferred(function (d) {
f.each({
done: [a, "resolve"],
fail: [c, "reject"]},
function (a, c) {
var e = c[0], g = c[1], h;
f.isFunction(e) ? b[a](function () {
h = e.apply(this, arguments), h && f.isFunction(h.promise) ? h.promise().then(d.resolve, d.reject) : d[g + "With"](this === b ? d : this, [h]);
}) : b[a](d[g]);
});
}).promise();
};
always: function () {
return b.done.apply(b, arguments).fail.apply(this, arguments);
};
then: function (a, c) {
b.done(a).fail(c);
return this;
};
promise: function (a) {
if (a == null) {
if (d) {
return d;
}
d = a = {};
}
var c = g.length;
while (c--) {
a[g[c]] = b[g[c]];
} return a;
};
isRejected: function () {
return !!c || !!b;
};
isResolved: function () {
return !!c || !!b;
};
fail: function () {
if (!d) {
var c = arguments, g, h, i, j, k;
b && (k = b, b = 0);
for (g = 0, h = c.length; g < h; g++) {
i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
}
k && e.resolveWith(k[0], k[1]);
}
return this;
};
done: function () {
if (!d) {
var c = arguments, g, h, i, j, k;
b && (k = b, b = 0);
for (g = 0, h = c.length; g < h; g++) {
i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
} k && e.resolveWith(k[0], k[1]);
}
return this;
};
success: function () {
if (!d) {
var c = arguments, g, h, i, j, k;
b && (k = b, b = 0);
for (g = 0, h = c.length; g < h; g++) {
i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
}
k && e.resolveWith(k[0], k[1]);
}
return this;
};
error: function () {
if (!d) {
var c = arguments, g, h, i, j, k;
b && (k = b, b = 0);
for (g = 0, h = c.length; g < h; g++) {
i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
}
k && e.resolveWith(k[0], k[1]);
}
return this;
};
complete: function () {
if (!d) {
var c = arguments, g, h, i, j, k;
b && (k = b, b = 0);
for (g = 0, h = c.length; g < h; g++) {
i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
}
k && e.resolveWith(k[0], k[1]);
}
return this;
};
statusCode: function (a) {
if (a) {
var b;
if (s < 2) {
for (b in a) {
j[b] = [j[b], a[b]];
}
} else {
b = a[v.status], v.then(b, b);
}
}
return this;
};
responseText: ;
status: 0;
statusText: error;
Thank you for your help