开发者

Fetch input value from certain class and send with jquery

<input id="u1" class="username">
<input id="u2" class="username">
<input id="u3" class="username">
...

How to fetch input value with "username" class and send with aj开发者_如何学Goax jquery to php page.

i want to recive data like simple array or simple json. (i need INPUT values and not ids)


var inputValues = [];
$('input.username').each(function() { inputValues.push($(this).val()); });

// Do whatever you want with the inputValues array


I find it best to use jQuery's built in serialize method. It sends the form data just like a normal for submit would. You simply give jQuery the id of your form and it takes care of the rest. You can even grab the forms action if you would like.

$.ajax({
  url: "test.php",
  type: "POST",
  data: $("#your-form").serialize(),
  success: function(data){
    //alert response from server
    alert(data);
  }
});


var values = new Array();
$('.username').each(function(){
    values.push( $(this).val());
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜