[Dojo-interest] POSTing JSON data cross-domain using CORS

Kris Zyp kris at sitepen.com
Tue Jan 7 23:23:10 EST 2014


Are you including Access-Control-Allow-Methods and Access-Control-Allow-Origin headers as well? It would probably be helpful to check the network log, to see what Access-Control-Request-* headers are on the OPTIONS request, as these determine which headers you need to specify on the response.
Thanks,
Kris
From: John Cartwright - NOAA Federal 
Sent: Tuesday, January 7, 2014 6:13 PM
To: dojo-interest 
Subject: [Dojo-interest] POSTing JSON data cross-domain using CORS

Hello All,

I'm trying to use dojo/request/xhr (version 1.9) to post some JSON data cross-domain.  I expected to have a pre-flight request due to the Content-Type header being set, but find that the request fails even when the server is setting 'Access-Control-Allow-Headers "X-Requested-With"'  The only way I can make it work is to change the Content-Type to "text/plain".  Example code listed below. 

Can someone please help me here?

Thanks!

--john


xhr("http://server.example.com/mapviewer-support/wcd/generateOrder.groovy", {
    handleAs: "json",
    data: JSON.stringify({"value":"testme"}),
    headers: {'Content-Type':'text/plain'},
    //headers: {'Content-Type':'application/json'},
    method: 'POST'
  }).then(function(data){
    // Do something with the handled data
    console.log(data.message);
  }, function(err){
    // Handle the error condition
    console.error(err);
  }, function(evt){
    // Handle a progress event from the request if the
    // browser supports XHR2
  });



--------------------------------------------------------------------------------
________________________________________________________
Dojo Toolkit: http://dojotoolkit.org/
Tutorials: http://dojotoolkit.org/documentation/
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api

Dojo-interest at mail.dojotoolkit.org
To unsubscribe, visit: http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-interest/attachments/20140107/d3f3c53c/attachment.htm 


More information about the Dojo-interest mailing list