【问题标题】:Crossdomain ajax action in Zend FrameworkZend 框架中的跨域 ajax 操作
【发布时间】:2023-03-12 20:34:01
【问题描述】:

我的应用程序(A)需要通过 AJAX(Fineuploader 库)将文件上传到我的子域(B)(物理上的其他服务器)。

我的解决方案是什么:在 B 上设置标头以允许来自 A 的请求。请参阅此控制器操作代码:

public function imageAction()
{
    $this->_response->setHeader('Access-Control-Allow-Origin', 'http://' . Zend_Registry::get('config')->main_server->path);
    $this->_response->setHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');

    $this->_helper->json(array('test'));
}

然后我尝试通过 A 的 ajax 调用此操作。请求具有下一个标头:

Request URL:http://sub.domain.dev/upload/image
Request Method:OPTIONS
Status Code:403 Forbidden
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:access-control-allow-origin, x-mime-type, origin, x-requested-with, cache-control, x-file-name, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:sub.domain.dev
Origin:http://domain.dev
Referer:http://domain.dev

我做错了什么?谢谢。

附: 当我发送带有这些标头的请求时:

Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Content-Length:0
Host:sub.domain.dev
Origin:http://domain.dev
Pragma:no-cache
Referer:http://domain.dev

我认为标题中的问题是由服务器发送的。

【问题讨论】:

  • 跨域ajax?你听说过 SOP 吗?
  • @Robert,当然,跨域 ajax。也许你能帮助我?这是可能的。但我与这些标题发生了争执。
  • @Jon,谢谢。我已经设置了这些标题。但没有运气:403 Forbidden。
  • 我找到了原因。 Apache 为 OPTIONS 方法返回 403 禁止访问。我该如何解决?

标签: php ajax apache cross-domain


【解决方案1】:

你试过使用这个 jquery 插件jQuery-File-Upload 吗?

Document page about cross-domain uploads.

【讨论】:

  • 我使用 Fineuploader。但是不要紧。我认为标题中的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-13
  • 2011-03-03
  • 1970-01-01
  • 2012-08-04
  • 2012-02-28
  • 1970-01-01
相关资源
最近更新 更多