开发者

Get values from form printed with smarty foreach

My problem is next:

I have a form where inputs, labels and some other tags are printed with smarty foreach. So i have a multiple tags with same name.

I need to collect data from some of fields in jquery. I am trying that on next way:

$('label#naziv_fajla').each(function(i){
        imena[i] = $(this).text();
//      console.log (i);
    });
console.log (imena); gives me next result: ["Desert.jpg", "Hydrangeas.jpg", "Koala.jpg", "Tulips.jpg"]

Then I need to send that data by ajax to a php script.

$.ajax({
        type: "POST",
        url: url,
        data: imena,开发者_如何学Python...

But it does not send me that data to php script. It looks like the format of that data is bad or something.

Please someone help me.

Thanks in advance.


the $.ajax data property can take an object of keys and values so I would loop through the inputs and put something like this:

$('input').each(function(i){//inputs in a certain container div
    imena[$(this).attr('name')] = $(this).val();
//  console.log (i);
});

This way all of the inputs name attribute will be what is in your $_POST variable

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜