Ramesh Pareek
Ramesh Pareek

Reputation: 1669

When does an ajax request in jquery consider an http post request successful?

Here is an excerpt from w3.org on http responses:

10.2 Successful 2xx

This class of status code indicates that the client's request was successfully received, understood, and accepted.

10.2.1 200 OK

The request has succeeded. The information returned with the response is dependent on the method used in the request, for example:

GET an entity corresponding to the requested resource is sent in the response;

POST an entity describing or containing the result of the action;

Is it considered "received, understood, and accepted" when the $_POST[] variables are stored in some other variable?

EDIT: here is the ajax call which calls an empty php file.

$.ajax({
    url: 'process.php',
    data: 'type=new&title='+title+'&startdate='+start+'&zone='+zone,
    type: 'POST',
    dataType: 'json',
    success: function(response){
                 event.id = response.eventid;
                 $('#calendar').fullCalendar('updateEvent',event);
                },
    error:  function(e){
                alert('Error processing your request: '+e.responseText);
                }
  });

and it calls the error part of the ajax call. But the console shows no errors. Now why it chooses only error and not success ??

Upvotes: 2

Views: 55

Answers (1)

lucian.nicolaescu
lucian.nicolaescu

Reputation: 647

You don't need to store anything... it's only about the response code. For example I can make a POST to a "script" that doesn't process anything, just a dummy empty file...

I don't really understand what's your "dilemma".

Upvotes: 3

Related Questions