如何复用json数据
我有 ajax 调用,它正在向我返回数据。
假设我有 ajax 返回数据
$.ajax({
url : "quoteSearch",
dataType : "json",
data : $("#searchCriteria").serialize(),
success : function(data) {
populateTable(data);
},
error : function(data) {
console.log(data);
}
});
现在我想使用这个表数据来更新 UI。
假设我在输入框中添加 10。然后单击“执行”按钮,它应该为该列的所有引号添加 10。
我该怎么做呢。
i have ajax call which is returning data to me .
Say i have ajax returning data
$.ajax({
url : "quoteSearch",
dataType : "json",
data : $("#searchCriteria").serialize(),
success : function(data) {
populateTable(data);
},
error : function(data) {
console.log(data);
}
});
Now i want to use this table data to update the UI.
Say if i add 10 to input box. and click go button it should add 10 to all quotes of the column.
How should i do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎在询问如何在非特定时间(具体取决于用户单击按钮的时间)从代码的另一部分使用 ajax 调用返回的
data
。如果是这样,您可以将data
保存在 ajax 调用范围之外的变量中,然后从代码的其他部分访问它:未定义的测试是允许您在 ajax 调用之前单击按钮已完成,此时
ajaxData
(显然)还没有值。您可能需要更新
populateTable()
函数,以便它采用带有要添加的值的参数。然后在 ajax success 中将该参数设置为 0,但在按钮单击处理程序中将该参数设置为输入的值。想必您的populateTable()
函数已经知道如何从data
检索值,因此您可以在该功能中进行额外的添加。如果没有看到您的其余代码,我真的无法提供更具体的建议。You seem to be asking how to use the
data
returned by the ajax call from another part of your code at a non-specific time depending on when the user clicks a button. If so, you can savedata
in a variable with scope outside the ajax call, then access it from other parts of your code:The undefined test is to allow for if you click the button before the ajax call has finished at which point
ajaxData
would (obviously) not yet have a value.You may want to update your
populateTable()
function so that it takes a parameter with the value to add. Then inside your ajax success you set that parameter to 0, but inside your button click handler you set that parameter to the value of your input. Presumably yourpopulateTable()
function already knows how to retrieve the values fromdata
, so you can do the extra addition within that functionality. I really can't advise anything more specific without seeing the rest of your code.在
populateTable
函数中,您应该使用$.each(data,function(k,v){ ... })
循环数据并使用值。如果不了解data
内部的内容或您尝试操作的 html 或populateTable
函数,就很难更具体地回答。inside your
populateTable
function, you should use$.each(data,function(k,v){ ... })
to loop over the data and use the values. Without seeing what is insidedata
or the html you are trying to manipulate, or thepopulateTable
function, it is difficult to answer more specifically.