473,513 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ajax from HTTP to HTTPS

3 New Member
On my page I have the FORM with one INPUT field. On SUBMIT this form I use JavaSript function "test_kod(this)" to valid is the the enetered value correct or not. But in the Internet Explorer ver <=9 the OPEN method allways fall with error "access denied".
WHAT AM I DOING WRONG?

Expand|Select|Wrap|Line Numbers
  1. function test_kod(field) {
  2.     var req = createXMLHTTPObject();
  3.     if (!req) { 
  4.         return false;
  5.     };
  6.     try {
  7.         //in IE <= 9 in this place debuger allways return error "access denied" 
  8.         req.open("GET","https://dad-atlas.datasolutions.pl/karta.php?karta="+field.value,false);
  9.     }
  10.     catch(e){
  11.         return false;
  12.     }
  13.     req.setRequestHeader('User-Agent','XMLHTTP/1.0');
  14.     req.onreadystatechange = function () {
  15.         if (req.readyState != 4) return;
  16.         if (req.status != 200 && req.status != 304) {
  17.             return false;
  18.         }
  19.         if (req.responseText == "TAK") {
  20.             return true;
  21.         } else {
  22.             return false;
  23.         };
  24.     }
  25.     if (req.readyState == 4) return;
  26.     req.send();
  27. }
  28.  
  29. var XMLHttpFactories = [
  30.     function () {return new XMLHttpRequest()},
  31.     function () {return new ActiveXObject("Msxml2.XMLHTTP")},
  32.     function () {return new ActiveXObject("Msxml3.XMLHTTP")},
  33.     function () {return new ActiveXObject("Microsoft.XMLHTTP")}
  34. ];
  35.  
  36. function createXMLHTTPObject() {
  37.     var xmlhttp = false;
  38.     for (var i=0;i<XMLHttpFactories.length;i++) {
  39.         try {
  40.             xmlhttp = XMLHttpFactories[i]();
  41.         }
  42.         catch (e) {
  43.             continue;
  44.         }
  45.         break;
  46.     }
  47.     return xmlhttp;
  48. }
  49.  
Mar 30 '14 #1
5 2451
Dormilich
8,658 Recognized Expert Moderator Expert
WHAT AM I DOING WRONG?
you’re not adhering to the SOP.

you’d either have to call a server script that requests the resource or you enable CORS.
Mar 30 '14 #2
kristofo
3 New Member
I digged in the NET and changed my script to use the XDomainRequest. It works good, but only if the url request has HTTP protocol. When I try to use url request with HTTPS protocol, in IE I still have the "access denied" error.

My new script.

Expand|Select|Wrap|Line Numbers
  1.     function test_kod(field) {
  2.       var xhr = createCORSRequest('GET', "https://dad-atlas.datasolutions.pl/karta.php?karta="+field.value);
  3.       //var xhr = createCORSRequest('GET', "http://facebook.com");
  4.       if (!xhr) {
  5.         alert('CORS not supported');
  6.         return false;
  7.       }
  8.       // Response handlers.
  9.       xhr.onload = function() {
  10.         var text = xhr.responseText;
  11.         var title = getTitle(text);
  12.         alert('Response from CORS request to ' + url + ': ' + title);
  13.       };
  14.  
  15.       xhr.onerror = function() {
  16.         alert('Woops, there was an error making the request.');
  17.       };
  18.  
  19.       xhr.send();
  20.     }
  21.  
  22.     // Create the XHR object.
  23.     function createCORSRequest(method, url) {
  24.       var xhr = new XMLHttpRequest();
  25.       if ("withCredentials" in xhr) {
  26.         // XHR for Chrome/Firefox/Opera/Safari.
  27.         xhr.open(method, url, true);
  28.         alert("Firefox open");
  29.       } else if (typeof XDomainRequest != "undefined") {
  30.         // XDomainRequest for IE.
  31.         xhr = new XDomainRequest();
  32.         xhr.open(method, url);
  33.         alert("IE open");
  34.       } else {
  35.         alert('CORS not supported');
  36.         xhr = null;
  37.       }
  38.       return xhr;
  39.     }
  40.  
  41.     // Helper method to parse the title tag from the response.
  42.     function getTitle(text) {
  43.       return text.match('<title>(.*)?</title>')[1];
  44.     }
  45.  
  46.  
Mar 30 '14 #3
Dormilich
8,658 Recognized Expert Moderator Expert
When I try to use url request with HTTPS protocol, in IE I still have the "access denied" error.
there’s probably not much to do then. does it work in other browsers?
Mar 31 '14 #4
kristofo
3 New Member
Yes, it works good in Firefox and IE ver > 9, But in IE <=9 I still have the "access denied" error.
I heard about same IFRAME method to get around this problem, but I don't know how to do it.
Mar 31 '14 #5
Dormilich
8,658 Recognized Expert Moderator Expert
since I'm hardly using CORS I don't know either. some google searches will have to do.
Apr 1 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
5152
by: Grunff | last post by:
I'm experiencing an interesting problem with carrying a php session over from http to https. Much googling later, I'm still stuck. The application is an online shop, where some user data is...
2
3129
by: MisterKen | last post by:
It appears that I'm losing values for session variables when I move from a page like http://www.my_site.com/catalog.aspx to https://www50.ssldomain.com/my_site/login.aspx and vice versa. Are...
4
1827
by: Chris Ashley | last post by:
Is it possible to persist viewstate information between HTTP and HTTPS (on the same page obviously)? Trying to get around writing some messy state transfer code... it doesn't seem to work if I use...
0
1506
by: Saverio Tedeschi | last post by:
Hi all gurus, I wrote an Win app with embedded FTP client (well, made some cut and paste from others' projects :-)) to receive and send files from within the app itself. Now the server I connect...
1
1280
by: bjohns33 | last post by:
Hi all I've written a custom provider for membership services and put my login control on an ascx. I want this ascx to be available anywhere on the website so that users don't need to click...
3
91290
by: sameergn | last post by:
Hi, Can anyone confirm is AJAX request can be sent over HTTPS if the containing page is loaded via HTTPS? or is it true that all AJAX interaction take place via HTTP? (Since the name of the...
1
3016
by: empiresolutions | last post by:
I am using this really neat and easy AJAX inline text edit script, http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/. It works great on localhost and HTTP. But, when i run...
4
3141
by: totalstranger | last post by:
My Bluehost site is setup with a dedicated IP address, Rapid SSL certificate, PHP 5 and FastCGI is set on. When switching between HTTP and HTTPS I was under the impression the Session Data was...
0
4040
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with...
1
5333
gregerly
by: gregerly | last post by:
I've got a question regarding how AJAX calls are handled over HTTPS pages. On my site, I've got a signup form that collects credit card info. It's a three part form, 1. Enter personal Info 2. Enter...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.