jQuery 表单插件 - 使用动态输入值循环提交
考虑以下设置:
- 在页面加载时创建的表单
现在,我设置了一个要循环的数组,该数组是根据 JSON 数据创建的。这一切都经过验证、检查并按预期工作。
我现在想做的是循环遍历数组以获得 Base64 编码的图像。我想用 PHP 来解码。为此,我想使用 post 方法来绕过 IE 浏览器的 URl 限制。
因此,在我的循环中,我使用 jQuery 表单插件将 #mybase64 表单提交到我的 PHP 文件。这一切几乎都有效。循环运行,调用 PHP 文件并更新目标元素中的图像。
问题 - 虽然我使用的是 for 循环,并且输入字段的值实际上得到了更新,但 jquery 表单在整个循环中不断提交相同的精确数据,尽管我更新了输入字段的值。
这就是我的做法,
for (var i = (JSpage - 1) * 12; i < JSresults; i++) {
if (!JSON[i].firstname) { var firstName = ' '; } else { var firstName = JSON[i].firstname; }
if (!JSON[i].lastname) { var lastName = ' '; } else { var lastName = JSON[i].lastname; }
if (!JSON[i].photo_base64) {
$('#ECbuttons').append('<li class="clickcontact" id="' + i + '"><img src="design_img/contact-no-image.jpg" /><div>' + firstName + '<br>' + lastName + '</div></li>');
} else {
//update input field
$('#basevalue').val(JSON[i].photo_base64);
//confirm that input field's value does change (check!)
var mi = $('#basevalue').val();
alert(mi);
//Add new li element to be updated with new image
$('#ECbuttons').append('<li class="clickcontact" id="' + i + '"><img style="height: 65px; width: 65px" src="" /><div>' + firstName + '<br>' + lastName + '</div></li>');
}
//dynamically set options for jQuery form submit
var options = {
//target is handled correctly and keeps getting updated with the same image
target: '#' + i,
url: 'system/showbase.php'
};
//submit the form on each run (check with a success handler, this gets called always
$('#mybase64').ajaxSubmit(options);
}
任何人都可以提供有关是否可以使用 ajax 表单请求从数组提交新数据的见解吗?如果可以,如何提交?
非常感谢您抽出时间
/Mikkel
Consider this setup:
- Form created on page load
<form id="mybase64" method="POST">
<input id="basevalue" name="basevalue" type="text" value="" />
</form>
Now I set up an array to be looped which I have created from JSON data. This is all verified, checked and works as expected.
What I want to do now is loop through the array to get a base64 encoded image. This I want to decode using PHP. To do this, I want to use a post method to get around URl limit for IE browsers.
Therefore, in my loop I am submitting the #mybase64 form using the jQuery Form plugin to my PHP file. All this almost works. The loop runs, the PHP file is called and an image is updated in the target element.
The PROBLEM - Although I am using a for loop, and the input field's value does in fact get updated, jquery form keeps submitting the same exact data through the entire loop, despite the fact that I update the input field's value.
Heres is how I do that
for (var i = (JSpage - 1) * 12; i < JSresults; i++) {
if (!JSON[i].firstname) { var firstName = ' '; } else { var firstName = JSON[i].firstname; }
if (!JSON[i].lastname) { var lastName = ' '; } else { var lastName = JSON[i].lastname; }
if (!JSON[i].photo_base64) {
$('#ECbuttons').append('<li class="clickcontact" id="' + i + '"><img src="design_img/contact-no-image.jpg" /><div>' + firstName + '<br>' + lastName + '</div></li>');
} else {
//update input field
$('#basevalue').val(JSON[i].photo_base64);
//confirm that input field's value does change (check!)
var mi = $('#basevalue').val();
alert(mi);
//Add new li element to be updated with new image
$('#ECbuttons').append('<li class="clickcontact" id="' + i + '"><img style="height: 65px; width: 65px" src="" /><div>' + firstName + '<br>' + lastName + '</div></li>');
}
//dynamically set options for jQuery form submit
var options = {
//target is handled correctly and keeps getting updated with the same image
target: '#' + i,
url: 'system/showbase.php'
};
//submit the form on each run (check with a success handler, this gets called always
$('#mybase64').ajaxSubmit(options);
}
Can anyone offer any insight as to wether it is possible to submit new data from the array using the ajax form request, and if so, how?
Thank you very much for your time
/Mikkel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论