JQuery.ajax不使用HTTPS [英] JQuery.ajax not using HTTPS

查看:269
本文介绍了JQuery.ajax不使用HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我使用.ajax方法从jQuery调用Web服务。调用该方法的页面是一个HTTPS / SSL页面,但是在调用时,jQuery会继续发出HTTP请求并且它失败了,因为服务器设置为将所有HTTP流量重定向到HTTPS ...所以301错误又回来了。

So, I am calling a web service from jQuery using the .ajax method. The page that is calling the method is an HTTPS/SSL page, yet when the call is made, jQuery keeps making an HTTP request and it is failing because the server is set up to redirect all HTTP traffic to HTTPS...so a 301 error is coming back.

我已经检查了我的代码一百万次并尝试了一百万种方法来生成ajax查询的url参数。 (使用//表示亲戚,现在只需将协议https附加到网址的开头。这是我的javascript:

I have inspected my code a million times and tried a million ways to generate the url parameter for the ajax query. (using // for relative and now just appending the protocol https to the beginning of the url. Here is my javascript:

function add_inbound_record(serial_number, pass_fail_value)
{
   pfv = pass_fail_value.toUpperCase();
   url = location.protocol + "//" + location.hostname + "/inbound/record-                 inspection/" + serial_number + "/" + pfv;
   $.ajax({
   url:url,
   cache:false,
   });
}

因此,当这段代码执行时,我会检查firebug中的url参数,并使用https和URL正确显示但是,当我执行ajax函数时,我在firebug中看到这个:

So, when this code executes, I check the url paramter in firebug and it shows up correctly with https and the URL properly formed. However, when I execute the ajax function I see this in firebug:

301 MOVED PERMANENTLY

192.168.1.9

20 B

192.168.1.9:443

Response Headersview source
Connection  keep-alive
Content-Encoding    gzip
Content-Length  20
Content-Type    text/html; charset=utf-8
Date    Wed, 24 Oct 2012 17:33:34 GMT
Location    http://192.168.1.9/inbound/record-inspection/011234567890123421000000002995/P/?_=1351100020609
Server  nginx/1.1.19
Vary    Accept-Encoding

Request Headersview source
Accept  */*
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Cookie  djdt=hide; csrftoken=sF9RUxrlS6IKURxOryH2d2yT05gMighn;         sessionid=9682390da4011e445931643c81be9aae
Host    192.168.1.9
Referer https://192.168.1.9/fingerprint/inspect/
User-Agent  Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:15.0) Gecko/20100101     Firefox/15.0.1
X-Requested-With    XMLHttpRequest

当你从引用者看到上面的协议,协议是HTTPS,但响应头中的位置是HTTP?我不能为我的生活弄清楚为什么请求作为HTTP而不是HTTPS通过网络。 301响应是准确的,因为它是作为HTTP进行的,因为Web服务器再次配置为仅允许HTTPS访问。有什么想法吗?

As you can see above from the referrer, the protocol is HTTPS yet the location in the response header is HTTP? I can't for the life of me figure out why the request is going across the wire as HTTP and not HTTPS. The 301 response is accurate considering it is going as HTTP since, again, the webserver is configured to only allow HTTPS access. Any ideas?

推荐答案

好的。我搞砸了这个超过4个小时,一旦我在URL的末尾添加了一个斜杠,问题就消失了,一切正常。我不知道为什么。 Web服务器/ Web服务不需要斜杠即可正常运行,但无论出于何种原因,这都是修复它的原因。感谢有用的评论家伙。

Ok. I messed with this for over 4 hours and as soon as I added a slash to the end of the URL, the issue went away and everything works fine. I have no idea why. The web server/web service does not require a slash to function correctly but for whatever reason, that's what "fixed" it. Thanks for the helpful comments guys.

这篇关于JQuery.ajax不使用HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆