开发者

jQuery ajax "data" field with mixed data

I have a form with some fie开发者_运维知识库lds in it:

<form id="unit">
  <input type="hidden" name="item_id" value="100" />
  <input type="hidden" name="name" value="item one" />
  <select name="option[1]">
    <option value="1">1GB</option>
    <option value="2">8GB</option>
  </select>
  <select name="option[2]">
    <option value="3">Red</option>
    <option value="4">Blue</option>
  </select>
</form>

I want to pass that data over jQuery ajax so I'm using:

$.ajax({
    type: 'post',
    url: 'index.php?route=product/options_plus_redux/updateImage',
    dataType: 'json',
    data: $('form#unit :input'),
    success: function (data) {
        //do something here...
    }
});

And that works fine. However, I want to add another bit of data along with the form fields. But I can't figure out the syntax for it. I know since the selectbox is named "option" there it will try to serialize that array. but basically I'm trying to do:

data: $('form#unit :input') +'x=test',

But it comes back very wrong

Any ideas?


try this:

data: $('form#unit').serialize() +'&x=test',

look up about jQuery form serialization

you can see it running here: http://jsfiddle.net/maniator/pfb2c/


var data = $('form#unit :input');
data.x = "test";
.......

url: 'index.php?route=product/options_plus_redux/updateImage',
dataType: 'json',
data: data,
.......
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜