javascript - jQuery.ajax() sends request more than once if headers object is set -


when run this, sends 2 requests reason. when remove headers object though runs once. why running twice headers object?

$.ajax({     type: "get",     headers: {         time: time     },     url: gethost() + "/leaderboard/top?gameid=" + gameid + "&token=" + createtoken([gameid, time]),     datatype: "json",     complete: function(data){         showoutput(json.parse(data.responsetext));     } }); 

when in chrome network inspector, see under method 1 says get , other says options. other request same.

on server have following headers set:

this.res.setheader("content-type", "text/json; charset=utf-8"); this.res.setheader("access-control-allow-origin", "*"); this.res.setheader("access-control-allow-headers", "origin, x-requested-with, content-type, accept, time"); 

under conditions(in case presents of time header) cross origin request pre-flight options request sent first make sure receiving server accepts these kinds of requests.

do reading on cross origin resource sharing , same origin policy.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -