weixin_33725270 2013-12-11 20:05 采纳率: 0%
浏览 103

jQuery Ajax通过https

I am having a problem with jQuery's ajax method over https.

The whole site is served over https. Most forms are submitted to a processing page via ajax. The url for the ajax function is basically:

$.ajax({
    "/assets/php/ajax/processor.php",
    ...
});

I also have a .htaccess file which redirects all http requests to https ones like so:

# Redirect any http requests to https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L]

The ajax works fine if I remove the redirect in the .htaccess file, but will not seem to work with it there. I assume this is because ajax functions over http (jQuery description of .ajax(): Perform an asynchronous HTTP (Ajax) request) and therefore the .htaccess redirect is catching the ajax request.

I need the redirect because I don't want users of the site to use the http version (there is a sign in header on every page) but i need the ajax to work too and be secured by https.

Thanks in advance for any help

  • 写回答

2条回答 默认 最新

  • weixin_33735676 2013-12-11 20:12
    关注

    Add the Access-Control-Allow-Origin to your server's headers:

    Access-Control-Allow-Origin: https://yoursite.com

    Then your original .htaccess file should work as expected.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧