简体   繁体   English

ajax url在https url上发布

[英]ajax url post on https url

Since I am using SSL connection in my website, I am trying to check the port where the user open the url (http/https): 由于我在网站上使用SSL连接,因此尝试检查用户打开URL(http / https)的端口:

if (isset($_SERVER['HTTPS']) &&
    ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
    isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
    $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
  $protocol = 'https://';
}
else {
  $protocol = 'http://';
}

It works great for the link of external file like css and js. 它非常适合外部文件(如css和js)的链接。

However, by checking the port, I am not able to post something with ajax. 但是,通过检查端口,我无法使用ajax发布内容。

 <input type='submit' value="LOGIN" onclick="return checkLogin()">

        function checkLogin() {
            var cUsername = $('[id$=userEmail]').val();
            var cPassword = $('[id$=userPassword]').val();
            var cartItems = cartItemsToJSON();

            var dataString = "username=" + cUsername + "&password=" + cPassword  + "&cartItems=" + cartItems;
            $.ajax({
                type: "POST",
                url: "<?php echo $protocol; ?>"+location.hostname+" /member/actions/config-login2.php",
                data: dataString,
                cache: true,
                success: function(html) {

When I click login, it doesn't run to the `config-lgin2.php, but it only shows my credential on the browser. 当我单击登录时,它不会运行到`config-lgin2.php,而是仅在浏览器上显示我的凭据。

I am wondering if I miss something here. 我想知道我是否想念这里的东西。 Help please. 请帮助。 Thanks in advance. 提前致谢。

Dont use fully qualified URLs, please try with a relative URI. 不要使用完全限定的网址,请尝试使用相对的URI。

Instead of specifying url as .... 而不是将url指定为...。

  url: "<?php echo $protocol; ?>"+location.hostname+" /member/actions/config-login2.php"

specify as, 指定为

  url: "member/actions/config-login2.php"

in the AJAX call 在AJAX通话中

If it does not work, JSONP is a nice alternative to look for 如果不起作用,JSONP是寻找的不错选择

Please view this post 请查看这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM