Reputation:
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
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
Reputation: 15497
$.ajax({
type: "POST",
url: "handler.php",
data: {
'action-type': 'remove_datacenter',
id: 2
}
});
Upvotes: 1