can anybody see why this ajax will not post the required data,
It still sucseeds and alerts , but no data is sent.
A normal ('#formid').submit will work , but obviously page refreshes
I require a non refresh. it is for a favorites button
But i cant understand why the data is not being sent.
the mysql and php is fine on the receiving page and works when i do a normal submit,
but when i try the ajax, it fails to send any data???
<form id='addfaveform' type='submit' action='favaddDB.php' method='POST' enctype='multipart/form-data'>
<input id='ListID2' type='hidden' name='listID2' value='' ></input>
<input id='UID2' type='hidden' name='UID2' value='' ></input>
<input id='accountname' type='hidden' name='accountname' value='' ></input>
</form>
<script>
function faveadd(fid){
var listingid="favicon["+fid+"]"
var variable_UID = undefined;
var variable_listID = undefined;
var variable_accountname = undefined;
var variable_UID = document.getElementById(listingid).getAttribute("data-variable-uid2");
var variable_listID = document.getElementById(listingid).getAttribute("data-variable-listID2");
var variable_accountname = document.getElementById(listingid).getAttribute("data-variable-accountname2");
// change input variables to post to view listing page
document.getElementById("UID2").value = variable_UID;
document.getElementById("ListID2").value = variable_listID;
document.getElementById("accountname").value = variable_accountname;
//document.getElementById("addfaveform").submit();
$.ajax({
type: 'post',
url: 'favaddDB.php',
data: $('addfaveform').serialize(),
success: function () {
alert('form was submitted');
}
});
};
php
cannot catch data because you did not give the ajax
data a name. for example:
PHP
code:
<?php
if(isset($_POST['data_name'])){
//Do somthing
}
?>
So, ajax
call should be like:
$.ajax({
type: 'POST',
url: 'favaddDB.php',
data: {'data_name': $('addfaveform').serialize()},
success: function () {
alert('form was submitted');
}
});
I think this will fix your problem.