<tfoot id='GUim7'></tfoot>
  • <i id='GUim7'><tr id='GUim7'><dt id='GUim7'><q id='GUim7'><span id='GUim7'><b id='GUim7'><form id='GUim7'><ins id='GUim7'></ins><ul id='GUim7'></ul><sub id='GUim7'></sub></form><legend id='GUim7'></legend><bdo id='GUim7'><pre id='GUim7'><center id='GUim7'></center></pre></bdo></b><th id='GUim7'></th></span></q></dt></tr></i><div id='GUim7'><tfoot id='GUim7'></tfoot><dl id='GUim7'><fieldset id='GUim7'></fieldset></dl></div>

    <small id='GUim7'></small><noframes id='GUim7'>

      • <bdo id='GUim7'></bdo><ul id='GUim7'></ul>
      <legend id='GUim7'><style id='GUim7'><dir id='GUim7'><q id='GUim7'></q></dir></style></legend>

      1. MooTools CORS 请求与原生 Javascript

        时间:2023-10-14
      2. <legend id='vow2Z'><style id='vow2Z'><dir id='vow2Z'><q id='vow2Z'></q></dir></style></legend>
            • <bdo id='vow2Z'></bdo><ul id='vow2Z'></ul>
              <tfoot id='vow2Z'></tfoot>

                    <tbody id='vow2Z'></tbody>

                  <small id='vow2Z'></small><noframes id='vow2Z'>

                1. <i id='vow2Z'><tr id='vow2Z'><dt id='vow2Z'><q id='vow2Z'><span id='vow2Z'><b id='vow2Z'><form id='vow2Z'><ins id='vow2Z'></ins><ul id='vow2Z'></ul><sub id='vow2Z'></sub></form><legend id='vow2Z'></legend><bdo id='vow2Z'><pre id='vow2Z'><center id='vow2Z'></center></pre></bdo></b><th id='vow2Z'></th></span></q></dt></tr></i><div id='vow2Z'><tfoot id='vow2Z'></tfoot><dl id='vow2Z'><fieldset id='vow2Z'></fieldset></dl></div>
                  本文介绍了MooTools CORS 请求与原生 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有这个 MooTools 代码:

                  I have this MooTools code:

                  new Request.JSON({
                    method: 'POST',
                    url: URL, /*URL TO ANOTHER DOMAIN*/
                    onSuccess: function(r){
                      callback(r);
                    }
                  }).post(data);
                  

                  并且此代码不发送 POST 请求(仅限 OPTIONS)...看看下面的代码(效果很好):

                  And this code doesn't send POST requests (OPTIONS only)... Look at the code below (it works great):

                  var http = null,
                    params = Object.toQueryString(data);
                  try {
                    http = new XMLHttpRequest();
                  } catch (e) {
                    try {
                      http = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                      try {
                        http = new ActiveXObject("Microsoft.XMLHTTP");
                      } catch (e) {
                        http = null;
                        alert("Your browser does not support AJAX!");
                      }
                    }
                  }
                  var url = URL;
                  http.onreadystatechange = function () {
                    if (http.readyState == 4 && http.status == 200) {
                      var jsonData = JSON.parse(http.responseText); /*OR EVAL*/
                      callback(jsonData);
                    }
                  };
                  http.open("POST", url);
                  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                  http.send(params);
                  

                  编辑:

                  试过:.setHeader('Content-Type','application/x-www-form-urlencoded');
                  还是什么都没有……哪里有问题?

                  Tried: .setHeader('Content-Type','application/x-www-form-urlencoded');
                  Still nothing... Where can there be a problem?

                  谢谢!

                  推荐答案

                  这是因为 MooTools 将一些额外的东西与请求标头捆绑在一起.

                  This is because MooTools bundles some extra stuff with the request headers.

                  例如.如果你的 htaccess 说:

                  eg. if your htaccess says:

                  Header set Access-Control-Allow-Origin: *
                  

                  您需要像这样制作您的请求:

                  you need to craft your request like that:

                  var foo = new Request({
                      url: 'http://fragged.org/Epitome/example/data/',
                      method: 'get',
                      onComplete: function (data) {
                          // returns an object with name and surname  
                          new Element('div[html="{name} {surname}"]'.substitute(JSON.decode(data))).inject(document.body);
                      }
                  });
                  
                  // need to remove that or CORS will need to match it specifically
                  delete foo.headers['X-Requested-With'];
                  foo.send();    
                  

                  这就是为什么您只能在飞行前看到 OPTIONS.它不喜欢你:)

                  This is why you are only seeing the OPTIONS pre-flight. It does not like you :)

                  您可以将 .htaccess 更改为也匹配 X-Requested-With,这可能是一些额外的安全性".

                  You could change the .htaccess to also match X-Requested-With, which is probably some extra "security".

                  有关工作示例,请参阅 http://jsfiddle.net/7zUSu/1/ - 我前段时间我想对 Request https://github.com 进行更改时这样做了/mootools/mootools-core/issues/2381 已修复.

                  See http://jsfiddle.net/7zUSu/1/ for a working example - I did that a while ago when I wanted to get this change to Request https://github.com/mootools/mootools-core/issues/2381 fixed.

                  这篇关于MooTools CORS 请求与原生 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:格式为 JS 时无布局渲染(需要晾干) 下一篇:传递“("和“)"通过 URI 导致 403 错误,我

                  相关文章

                  最新文章

                2. <small id='OdBvh'></small><noframes id='OdBvh'>

                  • <bdo id='OdBvh'></bdo><ul id='OdBvh'></ul>

                    <legend id='OdBvh'><style id='OdBvh'><dir id='OdBvh'><q id='OdBvh'></q></dir></style></legend>

                    <i id='OdBvh'><tr id='OdBvh'><dt id='OdBvh'><q id='OdBvh'><span id='OdBvh'><b id='OdBvh'><form id='OdBvh'><ins id='OdBvh'></ins><ul id='OdBvh'></ul><sub id='OdBvh'></sub></form><legend id='OdBvh'></legend><bdo id='OdBvh'><pre id='OdBvh'><center id='OdBvh'></center></pre></bdo></b><th id='OdBvh'></th></span></q></dt></tr></i><div id='OdBvh'><tfoot id='OdBvh'></tfoot><dl id='OdBvh'><fieldset id='OdBvh'></fieldset></dl></div>

                  1. <tfoot id='OdBvh'></tfoot>