javascript - CORS Support Not working with Domain -
i running google super proxy project on local server , trying pull json query data being hosted google appspot website.
http://usertest.appspot.com/query?id=ahjzfmnvbm5vcnbosdfsfewdsdxsaxbzmjryfqsscefwavf1zxj5gicagicagiakda
the issue keep running not allowed access webpage local server, because don't have cors support. have tried both javascript , jquery enable cors support, i'm still getting 2 error messages in console. know help?
1)
failed load resource: server responded status of 405 (method not allowed) http://usertest.appspot.com/query?id=ahjzfmnvbm5vcnboaweewwewxsaxbzmjryfqsscefwavf1zxj5gicagicagiakda
2)
xmlhttprequest cannot load http://usertest.appspot.com/query?id=ahjzfmnvbm5vcnboawxsaxbzmjreweadsdyfqsscefwavf1zxj5gicagicagiakda. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8888' therefore not allowed access.
index.html:
<!doctype html> <html> <head> <title>google super proxy test</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="chart-options.js"></script> <script src="chart.min.js"></script> </head> <body> <div style="width: 50%"> <canvas id="sessions-graph" height="450" width="600"></canvas> </div> </body> </html>
chart-options.js:
$.ajax({ type: 'get', url: 'http://usertest.appspot.com/query?id=ahjzfmnvbm5vcnboawxsaxbzmsdfsdfsjryfqsscefwavf1zxj5gicagicagiakda', contenttype: 'json', crossdomain: true, headers: { 'access-control-allow-origin': '*'}, success: function(data) { $.each(data, function(index, element) { alert(element.name); }) }, xhrfields: { withcredentials: true }, error: function (json) { debugger; } }); var barchartdata = { labels: [], datasets: [ { label: "my first dataset", fillcolor: "rgba(220,220,220,0.5)", strokecolor: "rgba(220,220,220,0.8)", highlightfill: "rgba(220,220,220,0.75)", highlightstroke: "rgba(220,220,220,1)", data: [] } ] }; var options = { //boolean - whether scale should start @ zero, or order of magnitude down lowest value scalebeginatzero : true, //boolean - whether grid lines shown across chart scaleshowgridlines : true, //string - colour of grid lines scalegridlinecolor : "rgba(0,0,0,.05)", //number - width of grid lines scalegridlinewidth : 1, //boolean - if there stroke on each bar barshowstroke : true, //number - pixel width of bar stroke barstrokewidth : 2, //number - spacing between each of x value sets barvaluespacing : 5, //number - spacing between data sets within x values bardatasetspacing : 1, //boolean - set if responsive or not responsive : true } window.onload = function(){ // context of canvas element var ctx = document.getelementbyid("sessions-graph").getcontext("2d"); var sessionsgraph = new chart(ctx).bar(barchartdata, options); //create chart "data" array };
access-control-allow-origin
response header.
the server asking give data has provide in http response. edit code responsible generating http://usertest.appspot.com/query
include it.
it not belong in request headers. script can't give permission access site.
by making request header, triggering preflight options request (which cause of method not allowed error).
Comments
Post a Comment