views:

87

answers:

3

I googled data.success, but I could not proper document. What is data.success in the following jquery? Is it javascript, jquery or json?

function remove_row(data){
     if(!data.success)
     return alert(data.error);
     $('#delete_link_'+data.id)
      .closest('li')
      .slideUp('slow',function(){
      $(this).remove();
});

--Edit--

Full jquery

$(document).ready(subscribers_init);
      function subscribers_init(){
       $('#subscribers li a:first-child')
        .click(delete_subscriber);
      }
      function delete_subscriber(){
       var id=this.href.replace(/.*=/,'');
       this.id='delete_link_'+id;
       if(confirm('Are you sure you want to delete this subscriber?'))
        $.getJSON('delete.php?ajax=true&id='+id, remove_row);
       return false;
      }
      function remove_row(data){
       if(!data.success)
        return alert(data.error);
       $('#delete_link_'+data.id)
        .closest('li')
        .slideUp('slow',function(){
         $(this).remove();
        });
      }

--Edit 2--

delete.php

$id=(int)@$_REQUEST['id'];
echo ( !($id%2) )?
    "{'id':$id,'success':1}":
    "{'id':$id,'success':0,'error':'Could not delete subscriber'}";

HTML

<ul id="subscribers">
<li>
<a href="delete.php?id=3">[x]</a>
<a href="user.php?id=3">Albertus Ackleton</a>
</li>
<li>
 <a href="delete.php?id=6">[x]</a>
 <a href="user.php?id=6">Bob Burry</a>
</li>
...
    ...
</ul>
+1  A: 

This looks like the callback after jQuery Ajax call. The "data" object that is passed in is the result of the ajax call, but its type will depend on the type of response you've asked for in your ajax call. You can specify an ajax request to return json, xml, html, text, etc. -- "data" will contain the results.

However, in this case, based on the usage, it looks like the Ajax call has returned JSON, which jQuery has turned into a javascript object (so that you can call properties of it such as "success").

JacobM
A: 

I guess ‘success’ is just a property of the data object, such as a flag. When deleting a row, do it on the server side first, set the flag. Then this function removes the row or shows the error message per this flag.

Estelle
A: 

success is part of the JSON data, that the request (delete.php) returned

frunsi