I’ve got a simple Ajax call using jquery:
jQuery(".deletebutton").on("click", function() {
if (confirm("Are you sure you want to delete?"))
{
jQuery.ajax({
url: 'index.php?option=com_recordings&task=deletevideos&format=raw',
type: "POST",
success: function(data){
console.log("anything?"); //never get here with FF and Chrome
if (data == 'blah')
{
alert("success"); //only with IE
}
}
});
}
});
The url is strange because I’m using Joomla component development. It essentially points to a file that has echo "blah";. The html is just a button with class deletebutton.
On IE this code works fine and the alert is fired. On FF and Chrome it doesn’t work. Checking the jqXHR.status shows that it returns 0. I don’t see anything in Firebug that points me to an issue here. Any idea what is going on?
EDIT: I noticed that it has something to do with my html button. The current button is inside a form:
<form name="myform" action="">
<table id="webcam-table" class="pretty">
<thead>
<tr>
<th>Camera Name</th>
<th>Date Created</th>
<th>Video Size</th>
<th>Video Length</th>
<th>
<input type="checkbox" name="checkboxselectall" title="Select All" />
<button class="deletebutton" title="Delete the selected videos" >Delete</button>
... //a table with checkboxes (for the form) and other stuff
</form>
But if I create a simple button outside this form my ajax call works as expected. What is going on here?
I successfully ran your code after updating my version of jQuery. The on() function was introduced in version 1.7. The following code worked. I passed the variables to blah.php, passed them back and echoed them out in the alert.
Here’s blah.php:
Here’s the contents of the body tags: