user470760
user470760

Reputation:

Jquery Ajax Post refuses to work

When attempting to use the JQuery Ajax post function, I have exhausted all the options I could think of for it to work. I just need to post the data to a PHP handler and pass 2 variables. I confirmed the function is being called fine when I comment out the post code (alert is called), but as soon as I uncomment the line, nothing happens. I am using Firefox but have also tried it with Chrome as well.

<script type="text/javarscript">
    function removeDatacenter( datacenter_id ) {    
        alert( datacenter_id );
        $.ajax({ 
           type: "POST", 
           url: "handler.php", 
           data: { action-type: 'remove_datacenter', id: '2' }
        });
    };
</script>

Upvotes: 1

Views: 94

Answers (2)

A. Wolff
A. Wolff

Reputation: 74420

You have to wrap action-type key object inside quotes because of '-' character:

You could rename it to ,e.g, actionType

$.ajax({ 
 type: "POST", 
 url: "handler.php", 
 data: { 'action-type': 'remove_datacenter', id: datacenter_id } 
})

Upvotes: 3

Manish Kumar
Manish Kumar

Reputation: 15497

$.ajax({ 
    type: "POST", 
    url: "handler.php", 
    data: { 
        'action-type': 'remove_datacenter', 
        id: 2
    } 
});

Upvotes: 1

Related Questions