Javascript 上一个Jquery事件设置的未定义值
我试图通过获取未定义的响应来发布一个带有动态设置值的表单,这是我的代码Javascript 上一个Jquery事件设置的未定义值,javascript,jquery,ajaxform,Javascript,Jquery,Ajaxform,我试图通过获取未定义的响应来发布一个带有动态设置值的表单,这是我的代码 $( ".paymentselect" ).click(function() { var bookingid=$(this).data('id'); $('#paymentstats').css('display','block'); $('#paymentform').attr('action', document.location.origin +"/accounts/" + bookingid)
$( ".paymentselect" ).click(function() {
var bookingid=$(this).data('id');
$('#paymentstats').css('display','block');
$('#paymentform').attr('action', document.location.origin +"/accounts/" + bookingid);
});
$('#paymentform').submit(function(event){
event.preventDefault();
var data=$('#paymentform').serialize();
$.ajax({
url: $(this).attr('action'),
method: 'POST',
data: data,
beforeSend: function() {
// setting a timeout
$('#wait').html('<i class="material-icons">cached</i>');
},
success: function(data){
if(data.status){
$('#paymentstats').css('display','none');
alert("UPDATED");
//location.reload();
}else
{
alert("something went wrong");
}
}
});
});
$(“.paymentselect”)。单击(函数(){
var bookingid=$(this.data('id');
$('#paymentstats').css('display','block');
$('#paymentform').attr('action',document.location.origin+“/accounts/”+bookingid);
});
$(“#paymentform”).submit(函数(事件){
event.preventDefault();
变量数据=$('#paymentform')。序列化();
$.ajax({
url:$(this.attr('action'),
方法:“POST”,
数据:数据,
beforeSend:function(){
//设置超时
$('#wait').html('cached');
},
成功:功能(数据){
if(数据状态){
$('#paymentstats').css('display','none');
警报(“更新”);
//location.reload();
}否则
{
警惕(“出了差错”);
}
}
});
});
POST上的bookingid未被查找很少有人愿意帮忙
编辑:
<table>
<tr>
<td>
<button class="paymentselect" data-id="NH7003687415654"> Update</button>
</td>
</tr>
<table>
<div id="paymentstats" class="custom-modal">
使现代化
//将要发布的表单
付款UTR(如有)
付款参考
提交
关
如上所述是我的html代码。
我已经尝试在单击事件时设置bookingpaymentid Val,但当表单在服务器上发布时,它也会显示未定义
我刚刚发现,当我发布表单时,该值变得未定义。由于您在
$(“.paymentselect”)中声明了bookingid
,因此有任何建议。请单击(函数(){
)。
<table>
<tr>
<td>
<button class="paymentselect" data-id="NH7003687415654"> Update</button>
</td>
</tr>
<table>
<div id="paymentstats" class="custom-modal">
您可以尝试以下方法:
var bookingid = null;
$( ".paymentselect" ).click(function() {
bookingid=$(this).data('id');
$('#paymentstats').css('display','block');
$('#paymentform').attr('action', document.location.origin +"/accounts/" + bookingid);
});
在plunker
bookingid
中未定义。请转到plunker并检查浏览器控制台以查看变量的值
您可能无法加载
脚本的顺序文件。正如您在plunker中看到的那样,请确保加载js
代码主体标记的末尾。您可以共享html吗?它的值是什么。paymentselect数据属性id,您可以详细说明吗?请共享您的html表单。我共享了html,您可以吗G有点事..谢谢@Yhose Widtantio,但我已经这么做了,但没有任何效果,这就是我在这里发布它的原因。为什么不在其中添加隐藏文本,然后在单击paymentselect时,将隐藏单击的值设置为$(this)。数据('id'))。您可以在上面看到,它们是一个隐藏的输入类型。在此期间已尝试过,但没有任何帮助。当我发布itif input HINDED时,它仍然未定义。您的意思是id=“bookingpaymentid”name=“id”。您从未设置id=“bookingpaymentid”的值,您可以在$(“.paymentselect”)内设置。单击(函数(){我发布的上述代码是您现在建议的前一个代码的替代代码。action attr是在click事件上设置的,但它仍然未定义。这与我设置隐藏输入值时的问题相同。