Click here to Skip to main content
14,271,663 members
Rate this:
Please Sign up or sign in to vote.
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

$.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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100