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

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

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

        MooTools CORS 请求与原生 Javascript

        MooTools CORS request vs native Javascript(MooTools CORS 请求与原生 Javascript)
        <i id='YCXHv'><tr id='YCXHv'><dt id='YCXHv'><q id='YCXHv'><span id='YCXHv'><b id='YCXHv'><form id='YCXHv'><ins id='YCXHv'></ins><ul id='YCXHv'></ul><sub id='YCXHv'></sub></form><legend id='YCXHv'></legend><bdo id='YCXHv'><pre id='YCXHv'><center id='YCXHv'></center></pre></bdo></b><th id='YCXHv'></th></span></q></dt></tr></i><div id='YCXHv'><tfoot id='YCXHv'></tfoot><dl id='YCXHv'><fieldset id='YCXHv'></fieldset></dl></div>

            <tbody id='YCXHv'></tbody>

              <bdo id='YCXHv'></bdo><ul id='YCXHv'></ul>

                <legend id='YCXHv'><style id='YCXHv'><dir id='YCXHv'><q id='YCXHv'></q></dir></style></legend><tfoot id='YCXHv'></tfoot>

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

                • 本文介绍了MooTools CORS 请求与原生 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有这个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
                  XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
                  Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
                  How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
                  How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
                  quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)

                  • <legend id='qE7IS'><style id='qE7IS'><dir id='qE7IS'><q id='qE7IS'></q></dir></style></legend>

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

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

                          <bdo id='qE7IS'></bdo><ul id='qE7IS'></ul>