0

I want to post the following content through Ajax. How can I do this ?

<form method="post" action="http://supersaas.com/api/users">
<input type="hidden" id="account" value="robintest">
 <input type="hidden" id="id" value="59fk"> 
<input type="hidden" id="user[name]" name="user[name]" value="[email protected]">
<input type="hidden" id="user[full_name]" name="user[full_name]" value="thomas">
<input type="hidden" id="user[phone]" name="user[phone]" value="">
<input type="hidden" id="user[address]" name="user[address]" value="">
<input type ="submit" name="submit" value="submit">
</form>

I tried the following code

 $.ajax({
 type: "post",
 url: "http://http://www.supersaas.com/api/users",
 data: {account:'sixcreeksTest', id:id,user[name]:name,user[address]:address}
 }).done(function( result ) {
 alert(result);
 });

but this gives syntax error..

I need to pass the variables as such because I am passing to an SAAS. So I don't have control over the server.

1
  • your json is not well formated for a javascript parser, [] signes are not allowed in property name for an object, the second solution from Jayantha is right formated. Commented Jul 25, 2013 at 3:46

2 Answers 2

1

You can pass the json object like this,

data: {account:'sixcreeksTest', id:id,checksome:checksome,user:{name:name,address:address}}

Or if you need to pass it as a form data instead of json, you can do like this,

data: {account:'sixcreeksTest', id:id,'user[name]':name,'user[address]':address}
Sign up to request clarification or add additional context in comments.

Comments

0

try serialize() to avoid mistakes

 $.ajax({
   type: "post",
   url: "http://http://www.supersaas.com/api/users",
   data: $('form').serialize(), 
   success: function(result) {
     alert(result);
   }
 });

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.