AJax¼¼Êõ

ajax֪ʶ AjaxѧϰȫÌ×(×îÈ«×î¾­µä)(4)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2016-12-25 11:00 ÎÒÒªÆÀÂÛ( )

×¢Ò⣺·þÎñÆ÷¶ËÏìÓ¦µÄ Access-Control-Allow-Origin ²»ÄÜÊÇͨÅä·û * !DOCTYPE htmlhtmlhead lang=en meta charset=UTF-8 title/title/headbody p input type=submit onclick=XmlSendRequest(); / /p p input type=s

•×¢Ò⣺·þÎñÆ÷¶ËÏìÓ¦µÄ Access-Control-Allow-Origin ²»ÄÜÊÇͨÅä·û *

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title></head><body> <p> <input type="submit" onclick="XmlSendRequest();" /> </p> <p> <input type="submit" onclick="JqSendRequest();" /> </p> <script type="text/javascript" src="jquery-1.12.4.js"></script> <script> function XmlSendRequest(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4) { var result = xhr.responseText; console.log(result); } }; xhr.withCredentials = true; xhr.open('PUT', ":8000/test/", true); xhr.setRequestHeader('k1', 'v1'); xhr.send(); } function JqSendRequest(){ $.ajax({ url: ":8000/test/", type: 'PUT', dataType: 'text', headers: {'k1': 'v1'}, xhrFields:{withCredentials: true}, success: function(data, statusText, xmlHttpRequest){ console.log(data); } }) } </script></body></html> class MainHandler(tornado.web.RequestHandler): def put(self): self.set_header('Access-Control-Allow-Origin', "") self.set_header('Access-Control-Allow-Credentials', "true") self.set_header('xxoo', "seven") self.set_header('zhangyanlinhenshuai', "feichangshuai") self.set_header('Access-Control-Expose-Headers', "shuai,shuaishuai") self.set_cookie('kkkkk', 'vvvvv'); self.write('{"status": true, "data": "seven"}') def options(self, *args, **kwargs): self.set_header('Access-Control-Allow-Origin', "") self.set_header('Access-Control-Allow-Headers', "k1,k2") self.set_header('Access-Control-Allow-Methods', "PUT,DELETE") self.set_header('Access-Control-Max-Age', 10)

ÒÔÉÏËùÊöÊÇС±à¸ø´ó¼Ò½éÉܵÄAjaxѧϰȫÌ×(×îÈ«×î¾­µä)µÄÈ«²¿ÐðÊö£¬Ï£Íû¶Ô´ó¼ÒÓÐËù°ïÖú£¬Èç¹û´ó¼ÒÓÐÈκÎÒÉÎÊÇë¸øÎÒÁôÑÔ£¬Ð¡±à»á¼°Ê±»Ø¸´´ó¼ÒµÄ¡£ÔÚ´ËÒ²·Ç³£¸Ðл´ó¼Ò¶Ô½Å±¾Ö®¼ÒÍøÕ¾µÄÖ§³Ö£¡

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • Java EE£ºAjax¼¼ÊõÔÚÄÄÀ

    Java EE£ºAjax¼¼ÊõÔÚÄÄÀ

    2016-12-25 12:08

  • ¡¾Ajax¡¿¡ª¡ªÑ§Ï°ºóµÄС½á

    ¡¾Ajax¡¿¡ª¡ªÑ§Ï°ºóµÄС½á

    2016-12-25 10:05

  • J2EE¿ª·¢¼¼Êõµã4£ºajax¼¼Êõ

    J2EE¿ª·¢¼¼Êõµã4£ºajax¼¼Êõ

    2016-12-24 17:00

  • AJAX¼¼Êõ½â¶Á

    AJAX¼¼Êõ½â¶Á

    2016-12-24 16:08

ÍøÓѵãÆÀ