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/ libidn/1.15 libssh2/1.2.6
Accept: application/json
Content-Type: application/json
Content-Length: 54
         "username": (1)"jsmith",
         "apiKey": (2)"aaaaa-bbbbb-ccccc-12345678"

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

                  url: '',
                  type: 'GET',
                  headers: { username: 'abc', apiKey: 'aaa-aaa-aaaa-aaa-aaaaa' },
                  success: function (data) {
                  error: function (result)
                  { alert('error:', result); }


1 solution

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

Solution 1

First of all read here:[^]
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
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
url: "",
beforeSend: function (xhr) {
xhr.setRequestHeader("Content-Type: application/json");
type: 'POST',
dataType: 'json',

// processData: true,
data: '{ "auth": { "RAX-KSKEY:apiKeyCredentials": { username: "abc", apiKey: "aaaaaaaaaaaaaaaaaaa" } } }',
success: function (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