开发者

JQuery Ajax not calling the page but everything else is working

I am trying to use JQuery to call a page which will delete a record from the database. The page (part_supplierDelete.php) works correctly when I test it manually. The JS & JQuery bellow all work except for the call to the page. When the deletePartSupplier() method is called the confirm dialog pops up and if you click ok the correct div is removed. But the record is not being deleted and it appears that the page is not being called at all. Any idea what I am doing wrong? I have tried with Chrome, FireFox, and IE 8.

function deletePartSupplier( part_supplier_id )
{
    var answer = confirm( "This action cannot be undone. Are you sure you want to remove this supplier from the part?" );
    if( answer )
    {
        $.post( "part_supplierDelete.php?part_supplier_id=".concat(part_supplier_id), removeElement( "PSID".concat(part_supplier_id) ) );
    }
}

function removeElement(divNum) {
  var d = document.getElementById('PartSupplierGroup');
  开发者_开发知识库var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}

*

---------- EDIT ----------- The page is showing up in the raw access log that it is being called. But it is not deleting the record like it should. I can follow the link in the access log and then it deletes the row like it should have.

Here is the access log:

/v3/part_supplierDelete.php?part_supplier_id=18
    Http Code: 200      Http Version: HTTP/1.1  Size in Bytes: 2
    Referer: /v3/partEdit.php?part_id=5
    Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10


Try replacing your $.post line with this:

$.post( "part_supplierDelete.php?part_supplier_id=" + part_supplier_id, function()
{
  removeElement( "PSID" + part_supplier_id );
}); 


The string concatenation operator in JavaScript is (stupidly) +, which is much easier and readable than calling concat().


Have you tried breaking up the $.post and instead of sending the POST as a GET, sending the data to be deleted as the second parameter for $.post?

This doc shows some examples: http://api.jquery.com/jQuery.post/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜