I use a function to post result via Ajax. When I test to see if the function was called I add an alert. Everything works fine, but as soon as I remove alert my results are not posted… What’s causing it?
function SendInvitesF(invType, invWho, projID) {
$.ajax({
url: "ajax.php",
type: POST",
data: "op=sendInvites&inviteMsgType="+invType+"&invitees="+invWho+"&proj="+projID
});
alert("test "+projID) // test alert <<<
}
$("#btnSend").click(function() {
if($("#customMsg").attr("checked")) {
var invType = "custom";
} else {
var invType = "default";
}
var invWho = $(".radioB:checked").val();
var projID = $("#testID").val();
SendInvitesF(invType, invWho, projID);
});
I suspect that you are calling this function in the onclick or onsubmit event and you are not canceling the default action by returning false. Also you are not properly url encoding any of your parameters. To do this use the data hash:
and then if you are calling this inside the onclick of an anchor:
Notice how we are returning false and thus canceling the default action which would be a redirect and of course not leaving the time for the AJAX request to execute. When you put an alert at the end of the function this stops any script execution and the AJAX call has the time to hit the server.