HTML 表单未使用 JQuery 填充
<script type="text/javascript">
$(document).ready(function() {
$(".edit").click(function(){
temp = $(this).attr('id').split("_");
$.get('/patients/getPlanofCareById', { "id": temp[1]},
function(data){
$('#patient-poc-frm').populate(data);
}, "json");
});
});
</script>
Firebug 发出表单元素不存在的通知,但我看到它们使用 firebug。我确信他们就在那里。您会注意到我使用 jquery 来发布变量并使用 json 发回结果。
任何
<script type="text/javascript">
$(document).ready(function() {
$(".edit").click(function(){
temp = $(this).attr('id').split("_");
$.get('/patients/getPlanofCareById', { "id": temp[1]},
function(data){
$('#patient-poc-frm').populate(data);
}, "json");
});
});
</script>
Firebug is throwing notices that the form elements do not exist but I see them using firebug. I am sure that they are there. You will notice that I am using jquery to post a variable and send back results using json.
Any
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅供那些可能在多年后仍然来到这里并正在寻找相同错误的人(就像今天的我一样:))。请注意 kbrin80 的评论,他说控制台输出显示“没有 [][id] 这样的元素” - 这是提示 - 至少对我来说是这样。例如我的代码看起来如何:
根据脚本
这第一眼看起来很棒,但发生的事情是我忘记了我的数据库框架返回一个包含原因数组中结果的数组 - 即使只返回一行 -仍然需要通过获取 $redsult[0] 来选择这一行。好吧,然后这个数组被转换成 json(通过 {} 周围的 [] 可见,并给出到 populate jquery 中——据我们所知,这是行不通的,因为在第一个位置,populate 需要 {id=>value} 而不是[{id=>value}] ({} 中的数组随后用于多选值)因此,您要做的就是找出数据库结果数组中您想要的值所在的位置,然后将其传递到json 编码器,然后填充。
像这样:
Just for people that probably still come here after years and are searching for the same error (like me today :) ). Notice kbrin80's comment where he says that the console output states "No such element as [][id]" - this is the hint - at least it was for me. e.g. how my code looked:
according script
This looks great in the first spot, but what happened is that I've forgotten that my DB-Framework returns an array containing results in an array of cause - even thogh there is only one row returned - still it is neccessary to choose this row by getting $redsult[0]. well, this array was then turned into json (visible by the [ ] around the {} and given into the populate jquery - which as we know doesn't work because in the first spot populate expects {id=>value} rather than [{id=>value}] (arrays within the {} are then used for multiselect values though) So what you want to do is figure out where in the array of your Database result the values you want are and just pass that into the json encoder and after that into populate.
Like this:
即使表单元素不存在,您也不应该收到错误。 jQuery 不是这样工作的,这意味着您看到的错误要么来自另一段 javascript 代码,要么您忘记包含 jQuery 库。
编辑
啊,你正在使用我看到的表单处理程序。我从来没有使用过它,但我确实注意到了一些事情:在发送 ajax 请求之前,您是根据下划线分割 id 属性的,对吧?您在 JSON 中发送的 ID 属性是后缀。生成的 JSON 在返回时是否会重新附加前缀?否则,如果 ID 最初类似于“textbox_name”,您将搜索 ID 为“name”的元素,但该元素不存在。
Even if the form elements don't exist you shouldn't be getting an error. jQuery doesn't work like that which means the errors you're seeing are either coming from another piece of javascript code or you've forgotten to include the jQuery library.
EDIT
Ah, you're using the form handler I see. I've never used it but I do notice something: Before you sent off the ajax request you're splitting the id attribute based on the underscore right? And the ID property you're sending in the JSON is the suffix. Is the resulting JSON appending the prefix back on when it returns? Otherwise if the ID was initially something like "textbox_name" you're going to be searching for an element with the ID "name" which won't exist.