两个 JSON 请求的列表
List of two JSON requests
我不明白如何做正确的事情。通过此查询,我得到了一个带有文件名的 JSON:
$.getJSON("http://api.server.com/my/?callback=?",
function(data){
var results = [];
$.each(data['results'], function(i, result) {
results.push("<div class='accordion-group span4'><div class='accordion-heading'>Video Frame<blockquote><a href='http://server.com/video/?my=" + result.File + "' target='_blank'><img src='http://jpg.server.com/" + result.File + ".jpg' class='img-polaroid'/></a><p>" + result.ListId + "</p><small>" + result.OwnerId + "</small><small>" + result.updatedAt + "</small> </blockquote><a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion2' href='#" + result.File + "'>Share video</a></div><div id='" + result.File + "' class='accordion-body collapse'><div class='accordion-inner'><form class='share_file_form'>Set list<input name='nd' id='user_id' type='hidden'><input name='file' value = '" + result.File + "' type='hidden'><div class='list'></div><input type='text' placeholder='New list'><div class='modal-footer'><button class='share_file_submit'>Share video</button></div></form><div id='user_info_result'></div></div></div></div>");
});
$('#mytile').html(results.join(""));
}
);
通过此查询,我得到了一个带有标签名称的 JSON:
$.getJSON("http://api.server.com/list/?callback=?",
function(data){
var results = [];
$.each(data['results'], function(i, result) {
results.push("<label class='radio'><input type='radio' name='list' id='" + result.List + "' value='" + result.List + "' checked>" + result.List + "</label>");
});
$('.my_list').html(results.join(""));
}
);
最后,我需要显示文件列表。每个文件旁边应显示一个带有文件名和标签列表的表单:
$(document).on('click', '.share_file_form', function() {
$('.share_file_form').validate({
submitHandler: function(form) {
$.ajax({
type: "GET",
url: "http://api.server.com/set/",
timeout: 20000,
data: $(form).serialize(),
beforeSend: function() {
$(".share_file_submit").attr("disabled", true);
$(".share_file_submit").html("Send <img src='http://src.server.com/loadr.gif' border='0'/>");
},
success: function(msg){
console.log("Data Saved: " + msg);
$("#share_file_submit").attr('disabled', false);
$("#share_file_submit").html("Share video");
$("#user_info_result_2").html(msg);
},
error: function(msg){
//////////////// $('#user_info_result_2').html("<div class='alert alert-error span3'>Failed from timeout. Please try again later. <span id='timer'></span> sec.</div>");
}
});
}
});
});
所有这些都有效。
问题是如何确保每个表单将单独工作?现在只适用于第一种形式。如果您按下其他表单上的按钮,第一个表单仍然有效。
您的错误在于您识别用户单击的表单的方式。以下行是问题所在:
$('.share_file_form').validate({
无论您单击的内容如何,您始终会使用此选择器获得第一个表单。
以下是您需要的:
$(document).on('click', '.share_file_form', function(event) {
$(event.target).validate({
submitHandler: function(form) {
嗯。我"认为"我知道你想要什么。
如何将第二个调用包装在一个方法中,或者两者兼而有之,ala。
function fireJSON(){
var func1 = function(){
//your first json code
func2(); // call your second json code
}
var func2 = function(){
// second json code
}
return {
func1: func1
}
}
fireJSON().func1();
相关文章:
- Ember-解决所有请求时显示列表
- 如何传递id列表's在MVC中向服务器发出AJAX请求
- AJAX请求php获取post/get发送的指定目录中服务器上的文件列表(无JQUERY)
- 通过REST API/GET请求订阅Mailchimp列表
- 所选列表元素不会保持选中状态(通过ajax请求更新后)
- node.js从http请求列表中将图像下载到服务器
- 将JSON REST请求加载到Kendo ui列表视图中的问题
- 两个 JSON 请求的列表
- 如何使用 javascript 访问保存在请求范围内的数组或列表
- 余烬 - 将 GET 请求发送到树列表的 API 端点
- 基于值 json 请求的加载列表
- 过滤列表并通过 ajax 请求数据
- 铬..在请求之前..() URL 列表无法按预期运行
- 离子列表无限滚动问题与Assinc请求
- XEP-0133:管理员请求获取所有在线用户列表
- 当处理请求发布ajax时,如何禁用该表单中的表单(用户无法检查、填写文本、选择下拉列表等)
- 获得viewCount播放列表项,结合HTTP请求youtube v3 + JQuery
- Ajax:批量url列表在文本区发送请求一个接一个,并显示重复的答案
- 使用下拉列表请求后的renderPartial
- PHP请求的多项选择列表