简体   繁体   English

输入中来自ajax jquery json调用的值隐藏

[英]value from ajax jquery json call in input hidden

I get data.my_id from an AJAX call. 我从AJAX调用中获得了data.my_id I want to place it inside a hidden input named my_id , but I am not able to do it. 我想将其放置在名为my_id的隐藏输入中,但无法执行。 Is there a special way to succeed with this sort of input? 是否有一种特殊的方法可以成功进行此类输入? Is it normal not to see the AJAX return in the sources of the page? 在页面的源中看不到AJAX返回是正常的吗? Thanks and sorry for my school English. 谢谢你,我学校的英语很抱歉。

// dat.my_id is working in an alert
$(#my_id).html(data.my_id);
<input type="hidden" name="my_id" id="my_id" value="<?= $my_id; ?>" />

You need to keep value of hidden empty initially. 您首先需要将hidden的值保持为空。

<input type="hidden" name="my_id" id="my_id" value="" />

Then on ajax response you can set the value as below: 然后,在ajax响应上,您可以将值设置如下:

$("#my_id").val(data.my_id);

To pass a value to your input you can use 要将值传递给输入,可以使用

$('#my_id').val(data.my_id);

Some examples 一些例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM