There have been similar questions, but I have browsed them a lot and found no accurate answer or fix so please offer a solution!
I am ajaxing a form to a page, and expecting a value back - no big deal. I've done it a million times before, but now it just refuses to work for this one form.
form html:
<form class="selectClaimType" action="place.php" method="post">
<select id="claimtype" name="claimtype">
<option value="privatebuilding">Private Building</option>
<option value="communalbuilding">Communal Building</option>
<option value="outside">Stored Outside</option>
</select>
<input type="submit" id="submit2" name="submit2" class="button" value="save"/>
</form>
jQuery:
$('form.selectClaimType').on('submit',function(e) {
console.log('found');
$form = $(this);
console.log($form.serialize());
e.preventDefault();
$.ajax({
url: "place.php", //$form.attr('action'),
type: "post", //$form.attr('method'),
data: $form.serialize(),
success: function(data) {
console.log(data);
if (data == 1) {
console.log('hello');
}
else {
console.log('failure to change claim type'+data);
}
},
data: function(data) {
console.log('error ajaxing'+data);
}
});
});
The form is not dynamically created, and as you can see I have console.log(ged) nigh on everything. So I know that the form.serialize() is working (values appear as expected). I left out the preventDefault() to test, and the get values were correct. I have tried dataTypes of script, html, text, xml and json - no success.
I have a var_dump of $_REQUEST and $_POST on the posted to page - these are both empty arrays. I have changed the page that the post is sent to - still doesn't work.
Any ideas at all?