简体   繁体   English

Ext.Ajax跨域发布请求

[英]Ext.Ajax Cross-Domain post request

I'm testing ExtJS v.5.1.0.107 and I my goal is that to perform a post ajax request on a different server. 我正在测试ExtJS v.5.1.0.107,我的目标是在另一台服务器上执行ajax请求。 I've found some similar discussions but nothing seems to work for my scenario. 我发现了一些类似的讨论,但似乎没有任何解决方案。 Here's request code: 这是请求代码:

    Ext.Ajax.request({
                                      url: 'http://192.168.1.60/test.php',
                                      method: 'POST',
                                      cors: true,
                                      useDefaultXhrHeader : false,
                                      params : {
                                          myPar1 : myPar1Value  
                                      },
                                      success: function () {
                                        alert('success');
                                      },
                                      failure: function () {
                                        alert('failure');
                                      }
                                    });

Here's error message: 这是错误消息:

XMLHttpRequest cannot load http://192.168.1.60/test.php . XMLHttpRequest无法加载http://192.168.1.60/test.php No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://192.168.1.50:22800 ' is therefore not allowed access. 因此,不允许访问源“ http://192.168.1.50:22800 ”。

Is there something wrong? 有什么不对? Hope someone can help me. 希望可以有人帮帮我。 Thanks to all. 谢谢大家。

Make sure your files are reachable from the server... 确保您的文件可以从服务器访问...

If the server is well configured, try add a response header for 如果服务器配置正确,请尝试添加以下响应标头

Access-Control-Allow-Origin: *

This command will allow cross-domain through Ajax operations. 此命令将允许通过Ajax操作进行跨域操作。 Then, the requested file (test.php for instance on the targeted server) should contain in the first lines : 然后,请求的文件(例如目标服务器上的test.php)应包含在第一行中:

<?php header('Access-Control-Allow-Origin: *'); ?>

Then, you should change parameter for Apache server hosting test.php file. 然后,您应该更改用于托管test.php文件的Apache服务器的参数。 In the .htacess file : 在.htacess文件中:

header set Access-Control-Allow-Origin "http://192.168.1.60/"

Hope this helps ! 希望这可以帮助 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM