Js-ajax发送到php检索html链接值
我有一个html链接,里面有这样一个值Js-ajax发送到php检索html链接值,php,ajax,twitter-bootstrap,modal-dialog,Php,Ajax,Twitter Bootstrap,Modal Dialog,我有一个html链接,里面有这样一个值 <a data-toggle='modal' data-id='1' href='#myModal' class='marker' title='Edit'>Link</a> 但有些地方出错,值未通过。请尝试 $('.marker')click(function(){ var myBookId = $().attr('data-id'); $.ajax({ type: "post",
<a data-toggle='modal' data-id='1' href='#myModal' class='marker' title='Edit'>Link</a>
但有些地方出错,值未通过。请尝试
$('.marker')click(function(){
var myBookId = $().attr('data-id');
$.ajax({
type: "post",
url: "update.php", //
data: myBookId,
success: function(msg){
$("#thanks").html(msg)
},
error: function(){
alert("failure");
}
});
return false;
});
您的问题在于AJAX调用的参数。试着这样做:
data: { myBookId: myBookId },
$('.marker')click(function(){
var myBookId = $().attr('data-id');
$.ajax({
type: "post",
url: "update.php", //
data: myBookId,
success: function(msg){
$("#thanks").html(msg)
},
error: function(){
alert("failure");
}
});
return false;
});
data: { myBookId: myBookId },