Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax : Why success displays 0?

I use ajax with jquery and when I tried to display the result in popup. Then alert always displays 0

success : function(results) { 
alert(results); }

EDIT :

 var dataToSend = {
    action:"ACTION_NAME",
    id : "12"
  };
  url_action = 'http://www.______.com/wp-admin/admin-ajax.php';
  $.ajax({
          url: url_action,
          type:'POST',
          data: dataToSend,
          success:function(results)
          {
             alert(results);
          }
   });
like image 494
Steffi Avatar asked Mar 20 '11 20:03

Steffi


People also ask

How do I know if AJAX request is successful?

You can check when exactly it returns "success" : // If successful, handle type chaining if ( status >= 200 && status < 300 || status === 304 ) { ... // If not modified if ( status === 304 ) { statusText = "notmodified"; ... // If we have data } else { try { ...

What does success mean in AJAX?

What is AJAX success? AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.

Why does AJAX call fail?

ajax method lets you set a timeout in milli seconds. When a timeout happens, The fail callback is called, with errorThrown set to "timeout". The request is aborted, meaning that even if the response arrives later on, your done callback is not called by jQuery.

Is AJAX successful deprecated?

The parameter is not being deprecated, the success method is. You can continue using success: function re-read it carefully.


1 Answers

Try to add die(); or exit(); at the very last line of the function.

like image 64
zourbuth Avatar answered Nov 13 '22 08:11

zourbuth