Datatables (Crossdomain)

Datatables (Crossdomain)

loloskiloloski Posts: 46Questions: 5Answers: 1

Hi Everyone,

I'm just wondering why datatables send extra OPTIONS request?, I noticed this ever since I've move my REST api to other subdomain resulting to 404.

at the moment JSONP is not an option for me for political reason.

This question has an accepted answers - jump to answer

Answers

  • loloskiloloski Posts: 46Questions: 5Answers: 1

    Additional Information I use slimframework as my REST api handler.

    $app->options('/ordersystem/joborder/listing',function() use($app) {
    $app->response()->header('Access-Control-Allow-Headers', 'X-Requested-With, X-authentication, X-client');
    });
    

    Return Response but to no avail still not working

    Access-Control-Allow-Head...    
    X-Requested-With, X-authentication, X-client
    Access-Control-Allow-Meth...    
    GET, POST, OPTIONS, DELETE, PUT
    Access-Control-Allow-Orig...    
    *
    

    But moving the API back to original domain fixed the issue, anyone has an idea? thanks a lot

  • allanallan Posts: 63,787Questions: 1Answers: 10,511 Site admin

    I don't see an options verb being send in this example.

    What does your browser's console say when you use the cross domain load? It should give an indication as to why it is working or not.

    Allan

  • loloskiloloski Posts: 46Questions: 5Answers: 1

    Hi allan,

    Don't bother I was able to fixed the issue, firebug lite didn't reveal much information whilst in chromium i was able to track down the issue because it's very verbose.

    the actual issue is I missed to set the Access-Control-Allow-Headers properly and Access-Control-Allow-Methods:

    For those interested this is how I do it.

    On server backend I have to modify the response header with proper response.

    header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type');
    

    On the API side (slimframework) i have to create a blank options routes which do nothing for each API method i have on my rest api.

    $app->options('/ordersystem/joborder/listing',function() use($app) {});
    $app->post('/ordersystem/joborder/listing',function() use($app) {
    /* 
    * Logic Code
    * 
    */
    });
    
  • allanallan Posts: 63,787Questions: 1Answers: 10,511 Site admin
    Answer ✓

    Awesome - thanks for posting that! I wonder if browser's might be using OPTIONS to check if their cache has gone stale...

    Either way, great to hear you've got it working!

    Allan

This discussion has been closed.