Results 1 to 4 of 4

Thread: Cant POST JSON data to https REST API via Ext.Ajax while GET is possible

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Jun 2012
    Vote Rating

    Default Answered: Cant POST JSON data to https REST API via Ext.Ajax while GET is possible


    Im trying to use Ext.Ajax to post some data as JSON to a Rest API server. Its a cross domain request but the server uses CORS. Im able to do GET and retrieve JSON data with no problems but when trying to do a POST it fails. In the following code I try to do a login
         login = function (callerInstance, user, pass, onLogin) {
            var url = SERVER + "login";
            var data = {};
            data.username = user;
            data.password = pass;
                url: url,
                method: 'POST',
                jsonData: data,
                success: function(response, opts) {
                    console.log(TAG + 'responseText: ' + response.responseText);
          , LOGGED_IN, response.responseText);
                failure: function(response, opts) {
                    console.log(TAG + 'server-side failure with status code ' + response.status);
                    console.log(TAG + 'responseText: ' + response.responseText);
          , NOT_LOGGED_IN, response.responseText);
    The result of this is
    HosRestApi: server-side failure with status code 0 
    And if I comment out the jsonData line, I get this error:
    HosRestApi: server-side failure with status code 500
    HosRestApi: responseText: {"errorText":"Internal Server Error: Object reference not set to an instance of an object."}
    So the server is trying to process the request but failing as there is no login data.
    So Im not sure why is the first error I mentioned happening or where is happening, or whats the problem.
    The URL is https, does that makes any difference?
    Please help me on this one!

  2. It was a CORS problem after all. To get my server supporting CORS Im using the following configuration:

    	<add name="Access-Control-Allow-Origin" value="*" />
    	<add name="Access-Control-Allow-Methods" value="GET, POST, DELETE, OPTIONS" />
    	<add name="Access-Control-Allow-Headers" value="origin, content-type, x-requested-with" />
    In the web.config file (its a IIS server). I hope this helps someone

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts