The success function of calling $.ajax receives a parameter, usually called data , although up to you containing the answer, like this:
success: function(data) {
(It also gets a few other parameters, if you want them, more in the docs .)
The type of the data parameter will vary depending on the type of response content sent by your PHP page. If it sends HTML, data will be a string containing HTML markup; if your page sends JSON , the data parameter will be a decoded JSON object; if it is XML, data will be an instance of an XML document.
You can use 1 or 0 if you want (if you do, I would probably set the content type to "text / plain"), so:
success: function(data) { if (data === "1") { // success } else if (data === "0") { // failure } else { // App error, expected "0" or "1" } }
... but when I answer Ajax requests nine times out of ten, I send JSON back (so I set the Content-Type header to application/json ), because then if I use a library like jQuery that understands JSON, I I will return to a good ordered object that is easy to work with. I'm not a PHP guy, but I believe that you set the content type through setContentType and use json_encode to encode the data to send back.
In your case, I would answer:
{"success": "true"}
or
{"success": "false", "errMessage": "You reached the limit."}
so that the server code can determine which error message I will show the user. Then your success function will look like this:
success: function(data) { var msg; if (typeof data !== "object") { // Strange, we should have gotten back an object msg = "Application error"; } else if (!data.success) { // `success` is false or missing, grab the error message // or a fallback if it missing msg = data.errMessage || "Request failed, no error given"; } if (msg) { // Show the message -- you can use `alert` or whatever } }