hye i have an ajax call which is not working and i don't know why
my ajax call is
function insertData(icompany,iproduct,iavailability,irelatedInformation,ishortageReason,idateUpdated)
{
alert('here')//comes here just once but i have a loop which calls insertData function
$.ajax({
url: '../includes/drugShortage.php',
data: {
action:'insert' ,
company: '\'' + icompany +'\'',
product: '\'' + iproduct+'\'',
availability: '\'' + iavailability+'\'',
relatedInformation: '\'' + irelatedInformation+'\'',
shortageReason: '\'' + ishortageReason+'\'',
dateUpdated: '\'' + idateUpdated+'\''
},
success: function(e)
{
alert(e);
},
error:function(e)
{
alert(e);
},
type:GET
});
}
i don't know what is causing this.
The value for "type"
attribute should be quoted. Additionally, there is no need to specify the type for jQuery ajax
call. The default value is "GET"
. Also I will recommend you to turn on error reporting for Javascript in the browser and check console for script errors. It will help you a lot.
I would use setTimeout to call function periodically! I hopw this code will give you some hint for your assignment!
<script type="text/javascript">
$(document).ready(function() {
window.setTimeout(function() {
insertData("", "", "", "", "", ""); //Pass Data Here...!!!
}, 1000); //Call every 1 min
});
function insertData(icompany, iproduct, iavailability, irelatedInformation, ishortageReason, idateUpdated) {
$.ajax({
type: "GET"
url: "../includes/drugShortage.php",
data: {
action: "insert",
company: icompany,
product: iproduct,
availability: iavailability,
relatedInformation: irelatedInformation,
shortageReason: ishortageReason,
dateUpdated: idateUpdated
},
success: function(event) {
//TODO
},
error: function(e) {
//TODO
}
});
}
</script>