Fairly new to Javascript, inherited a web site, trying to decipher how this function works. By the way, If I am not including code the proper way, please tell me how I should be doing it, happy to learn the right way.
function del(item_id) {
if(confirm(‘Are you sure you want to delete this item?’)) {
$.post(“<?=$_SERVER[‘PHP_SELF’]?>”, {
id:item_id,
action:’delete’,
callback: function(data, textStatus) {
$(“#faqs
}
});
}
}
This function confirms/cancels the Delete action, then refreshes the screen to update the list of records. It does not do the actual deletion; that is in HTML and PHP.
The function works in one location on my site, and was copied to another. While the actual deletion of the data record works fine on the new page, the refresh of the screen is not working.
Obviously, the $_SERVER[‘PHP_SELF’] portion of the code is never executed. Trying to learn why.
There are two variables in the function: item_id and “#faqs_”. I can confirm item_id is a legit value; it is not the problem.
I do not know what “#faqs_” is all about. Clearly, it is related to the actual page (the function came from a page all about FAQS about the company), but I can find NO variables, table, field, anything else that uses this same name. It seems to be just a marker of some sort.
So, I am not understanding what the callback: function (…) is trying to do, what data it needs to do it, and what I should replace “#faqs_” with.
Any ideas how this function works, what I might try in place of #faqs_?
Just for clarification:
This function is called from an HTML form as:
<div class=”delete”><input type=”button” class=”button” value=”Delete” onclick=”del(<?=$vers_obj->id?>)” /></div>
This code works; ‘$vers_obj->id’ is a valid record number.
The actual Delete function is a PHP function and deletes the record appropriately. The delete() function is a commonly used PHP function used successfully throughout the site.
Thanks very much appreciated,
tc