santa santa - 6 months ago 9
Javascript Question

How to test AJAX post with jQuery

I have the following function that opens jQuery UI's dialog warning about the delete of an entry. Everything works fine, except the POST with AJAX. I get response on "success" but I don't believe I am hitting the .php page that is supposed to execute the query. Am I missing anything here?

var $dialog = $("#dialog").dialog({ autoOpen: false, resizable: false, modal: true });

$(".delProj").click(function(){
var delURL = $(this).attr("href").split("#");
var projID = delURL[1];
$dialog.dialog("open");
$("#dialog").dialog({
buttons: {
"Yes, delete this test": function() {
$.ajax({
type: "POST",
url: "http://www.example.com/inc/db_actions.php",
data: "op=DeleteProject&delete="+projID,
success: function(){
// alert( "Test Project deleted successfully." );
$("#"+projID).remove();
}
});
$(this).dialog("close");
},
"No, keep it.": function() {
$(this).dialog("close");
}
}
});
});

Answer

Make your php page called echo something

PHP

echo 'hello world';

Javascript

Add the return value of the callback (here data), and try to show it with js.

[..]

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

[...]