Ajax post request question

edited July 2013 in Newbie Questions
I am trying to execute the following using enyo.ajax.
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

This is my code
var ajax = new enyo.Ajax({
                        url: 'https://accounts.google.com/o/oauth2/token',
                        method: 'POST',
                        contentType: 'application/x-www-form-urlencoded',
                        postBody: {
                                   code: code[1],
                                   client_id: myclient_id,
                                   client_secret: myclient_secret,
                                   redirect_uri: redirect_uri,
                                   grant_type: 'authorization_code'
          ajax.response(this, "processResponse");
          ajax.error(this, "processError");
I have verified all information and they are correct, but ajax.error is called every time. I was not sure if I used postBody parameter correctly. Please help me out here. Thank you


  • What error code are you getting? Have you watched this transaction in the Network tab of Web Inspector?
  • edited July 2013
    I am getting error code 400
  • edited July 2013
    I have made this work using jquery. The code for that is as follows. I am just trying to use enyo.ajax. From the following code, I am able get the data I need. Here is the code that works for me.
    $.post('https://accounts.google.com/o/oauth2/token', {
                          code: code[1],
                          client_id: options.clientId,
                          client_secret: options.clientSecret,
                          redirect_uri: options.redirectUri,
                          grant_type: 'authorization_code'
                          }).done(function(data) {
                              var theUrl = 'https://www.googleapis.com/drive/v2/files?access_token=' + data.access_token;
                              $.get(theUrl, function(data) {
                          }).fail(function(response) {
                              alert("Failed to connect")
  • Hey unwiredben ... I figured out the problem ... thanks anyways for your help. The issue is with postBody. I changed it to this postBody: 'code=' + code[1] + '&client_id=' + client_id .... and so on.
  • I suspect the issue might be that Enyo defaults to using cache buster methods which add a random numeric string to the URL. Instead of building your own postBody, try setting the "cacheBust: false" property for the enyo.Ajax object.
Sign In or Register to comment.