Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
153
rated 0 times [  154] [ 1]  / answers: 1 / hits: 18706  / 12 Years ago, wed, october 24, 2012, 12:00:00

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.



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,
});
}


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


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?


More From » jquery

 Answers
31

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.


Example note the double slash


Before:
https://somedomain.com//requests/get-requests.html?lang=ar


After (fixed):
https://somedomain.com/requests/get-requests.html?lang=ar


UPDATE:
Issue came back to me meaning after it became working
when i removed the slash!


Then this answer saved my day too
https://stackoverflow.com/a/71382206/944593


[#82372] Tuesday, October 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byron

Total Points: 616
Total Questions: 101
Total Answers: 91

Location: Reunion
Member since Wed, Apr 14, 2021
3 Years ago
;