I’m trying to submit a form with AJAX through jQuery:
$('.submit input').click(function() {return false;});
$("#addcourseform").submit(function(event) {
event.preventDefault();
var formcont = $(this).serialize();
$.post({
type:"POST",
url: "<?php echo base_url(); ?>handover/courseadd",
data: formcont,
success: function(returned) {
alert("It worked: "+returned);
}
});
});
This above code is wrapped in ready(), returns no errors in the console, and all that good stuff. However, it seems to append [object Object] to the end of the POST url. Since I use CodeIgniter, that throws a 400 Bad Request because it includes disallowed characters in the URL.
How do I get jQuery from adding that?
EDIT POST-FIX:
For those future people reading this and thinking I’m an idiot, I did in fact use the post() syntax wrong.
$.post is not the same as $.ajax so you have to provide the parameters differently.
Try this:
Or just replace post with ajax in your current code.