Search code examples
phpjqueryajaxpostphpstorm

jQuery $.post Syntax


I am using phpStorm to edit a file. This code breaks the page:

$("#delete_all_button").click(function(){
    var oTT = TableTools.fnGetInstance( 'pickup_list_all' );
    var selectedRows = oTT.fnGetSelectedData();

    first = selectedRows[0][selectedRows.length-1];
    $.post("delete.php", {'claimID': first}, function(data){
        console.log(data);
    });
});

Specifically the colon inbetween claimID and first. When I hover overtop a red squiggly underneath the colon, the editor tells me "} expected". When I try and load the page, I get no error in the console and the page is just white.

Another important thing to note is that when I copy previously working post code from another file which has no errors in the code to this file, the errors appear.

What could be the problem? Libraries?

I have imported jquery with the following line:

<script type="text/javascript" charset="utf-8" src="js/jquery-1.7.2.min.js"></script>

Thanks!


Solution

  • The data parameter of jquery.post() expects "A map or string that is sent to the server with the request." You could try changing the second parameter to JSON.stringify({'claimID': first}) or wrap it in brackets to make it an array [{'claimID': first}]