有人知道为什么这个ajax不会发布所需的数据吗,
它仍然会发送消息和警报,但不会发送任何数据。
一个普通的(“#formid”).submit可以工作,但显然页面会刷新
我需要不刷新。这是一个收藏夹按钮
但是我不明白为什么数据没有被发送。
mysql和php在接收页面上很好,在我正常提交的时候也能正常工作,
但是当我尝试ajax时,它无法发送任何数据???
<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');
}
});
};
1条答案
按热度按时间uujelgoq1#
php
无法捕获数据,因为您没有提供ajax
数据名。例如:PHP
代码:所以,
ajax
电话应该是这样的:我想这会解决你的问题。