Results 1 to 5 of 5

Thread: How to make an ajax request cross origin CORS

  1. #1
    Sencha User SurenderBhyan1's Avatar
    Join Date
    Nov 2013
    Location
    INDIA
    Posts
    130

    Default How to make an ajax request cross origin CORS

    Ext JS 4.2.1
    Chrome

    I am trying first time to make an ajax request with CORS. But getting the below error in console and request fails.

    Below is two fiddle (Sencha Fiddle, JS fiddle), Both have different error in console.

    Sometime its gives Access-Control-Allow_Origin error
    Fiddle: https://fiddle.sencha.com/#fiddle/kvu

    http://jsfiddle.net/SurenderBhyan1/vdazU/849/

    CORS.jpg


    Please help where I am missing the flow. You can try with different ajax URL.

    Thanks in advance
    ---A ship in the harbor is safe, but that is not what the ships are made for...

  2. #2
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579

    Default

    Hi,

    To make an AJAX request using CORS, the server needs to be configured to accept cross-origin requests. You can read more about enabling that here if it's not already available on your server: http://enable-cors.org/

    You'll also need to enable CORS on the Ajax class for the request. In this example, the request still fails as the protocols differ (https vs http) and the destination does not appear to be configured to allow your request.



    Hope this helps,
    Tristan

  3. #3
    Sencha User SurenderBhyan1's Avatar
    Join Date
    Nov 2013
    Location
    INDIA
    Posts
    130

    Default

    Thank You Tristan. Reference provided by you helped a lot me and I was missing the headers for origin from server side .

    Here is another fix using Jquery Ajax

    Code:
    $.ajax({
                url: 'http:ww.abc.com?callback=?',
                dataType: 'JSONP',
                jsonpCallback: 'callbackFnc',
                type: 'GET',
                async: false,
                crossDomain: true,
                success: function () { },
                failure: function () { },
                complete: function (data) {
                    if (data.readyState == '4' && data.status == '200') {
                        errorLog.push({ IP: Host, Status: 'SUCCESS' })
                    }
                    else {
                        errorLog.push({ IP: Host, Status: 'FAIL' })
                    }
                }
            });
    ---A ship in the harbor is safe, but that is not what the ships are made for...

  4. #4
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579

    Default

    Glad to have helped!

  5. #5

    Default How to load data in viewModel Store using Ext Ajax Request.

    when i trying to load data in viewModel store using Ext.Ajax.Request .

    viewModel :

    stores : {
    unitdetailswaybills : {
    autoLoad : true,
    proxy: {
    type: 'memory',
    data : [],

    reader: {
    type: 'json',
    rootProperty: 'wayBill'
    }
    }
    }
    }


    Controller :


    Ext.Ajax.request({
    url: '10.155.105.41:8080/fleeet/getSummaryData',
    method: 'GET',
    headers: {
    'Content-Type': 'application/json'
    },
    params: Ext.JSON.encode(formPanel.getValues()),
    success: function(response) {
    var myText = Ext.encode(response.responsetext);
    var myString = JsoN.strinfy(myText);
    var myData = Ext.JsON.decode(myString);
    var myStore = this.getViewModel().getStore('unitdetailswaybills');
    myStore.loadRawData(myData);
    },
    failure: function(response) {}
    });

    Note :


    This is the way i tried ,

    but the data is not loaded properly in viewModel Store.

    Please tell me how to resolve this issue.

    Thanks in Advance,

Similar Threads

  1. Replies: 8
    Last Post: 26 Jun 2017, 3:30 AM
  2. CORS - Cross Origin Resource Sharing article
    By iphonewhit in forum Sencha Touch 2.x: Discussion
    Replies: 3
    Last Post: 23 Sep 2013, 9:43 PM
  3. (CORS) Cross-Origin Resource Sharing requests
    By luismerino in forum Sencha Touch 2.x: Discussion
    Replies: 13
    Last Post: 2 Jul 2012, 12:29 AM
  4. Cross domain Ajax Request without Allow Access origin *
    By mvirtism in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 21 Jun 2012, 11:22 PM
  5. Cross Origin issue / is Sencha doing something special for CORS?
    By marceloverdijk in forum Sencha Touch 2.x: Discussion
    Replies: 5
    Last Post: 28 Mar 2012, 6:36 AM

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
  •