0
<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 ajax jquery to php page.

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

3 Answers 3

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

// Do whatever you want with the inputValues array
Sign up to request clarification or add additional context in comments.

Comments

1

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);
  }
});

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.