1

I'm trying to use jQuery's $.post() method with variables from values taken from textboxes on the page. My code looks like this:

$.post("install-ajax.php", { host: $("#host").val(), user: $("#user").val(), pass: $("#pass").val(), name: $("#name").val() }, function(data) { $("#post").append(data); }); 

So far, the request hasn't worked at all. Is this possible to do? If so, what do I have to do to make it work?

Thanks very much in advance! :)

1
  • Please elaborate on what exactly isn't working... Commented Dec 5, 2010 at 5:42

1 Answer 1

2

Judging from the variables that you want to send via Ajax, I'd suggest trying the following:

function construct_vars_from_ids(vars) { var obj = {}; jQuery.each(vars, function(index, el) { obj[el] = $('#' + el).val(); }); return obj; } $.post("install-ajax.php", construct_vars_from_ids(['host', 'user', 'pass', 'name']), function(data) { $("#post").append(data); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

I faced the same problem and thanks for the solution and I want to know why the way that @esqew used is not working

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.