Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi developers I am new in ajax and first time consuming web api .
This is my json object to authenticate a user . how can i pass this in ajax call to get the authenticate token please help me
POST /v2.0/tokens HTTP/1.1
User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
Host: identity.api.rackspacecloud.com
Accept: application/json
Content-Type: application/json
Content-Length: 54
 
{
   "auth":
   {
      "RAX-KSKEY:apiKeyCredentials":
      {
         "username": (1)"jsmith",
         "apiKey": (2)"aaaaa-bbbbb-ccccc-12345678"
      }
   }
}



I am doing this but not able to consume please give me some solution

JavaScript
$.ajax({
                  url: 'https://identity.api.rackspacecloud.com/v2.0/tokens',
                  type: 'GET',
                  datatype:'application/json',
                  headers: { username: 'abc', apiKey: 'aaa-aaa-aaaa-aaa-aaaaa' },
                  success: function (data) {
                      alert('hi');
                  },
                  error: function (result)
                  { alert('error:', result); }

              });
Posted

1 solution

First of all read here: http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/QuickStart-000.html[^]
The things you can understand immediately (and you can see it even in your sample) that the type should be POST and never GET!
The samples in the link use curl, so some hints...
-d in curl is data
-H in curl is header
 
Share this answer
 
Comments
Member 10952217 7-Jun-15 4:52am    
i have read all detail but question is that how to convert curl into ajax
Kornfeld Eliyahu Peter 7-Jun-15 4:54am    
Ask Google - you will find endless samples...
Member 10952217 7-Jun-15 6:16am    
$.ajax({
url: "https://identity.api.rackspacecloud.com/v1.0/tokens",
beforeSend: function (xhr) {
xhr.setRequestHeader("Content-Type: application/json");
},
type: 'POST',
dataType: 'json',
accept:'application/json',

// processData: true,
data: '{ "auth": { "RAX-KSKEY:apiKeyCredentials": { username: "abc", apiKey: "aaaaaaaaaaaaaaaaaaa" } } }',
success: function (response) {
alert(JSON.stringify(response));
},
error: function () {
alert("Cannot get data");
}
});

If you know please suggest me i am doing this but not getting success

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900