开发者

jQuery form plugin - Looping submits with dynamic input value

开发者 https://www.devze.com 2023-03-05 07:06 出处:网络
Consider this setup: Form created on page load <form id=\"mybase64\" method=\"POST\"> <input id=\"basevalue\" name=\"basevalue\" type=\"text\" value=\"\" />

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 dat开发者_C百科a from the array using the ajax form request, and if so, how?

Thank you very much for your time

/Mikkel

0

精彩评论

暂无评论...
验证码 换一张
取 消