简体   繁体   English

手机上的jQuery ajax跨域请求

[英]jQuery ajax crossdomain request on mobile phone

I am writing kind of an API to get a login panel from my own server. 我正在编写一种API,以从我自己的服务器获取登录面板。 The plan is, that every domain, which I allow in my PHP header 计划是每个域,我在PHP标头中允许

header("Access-Control-Allow-Origin: externaldomain.com")

can access the login panel. 可以访问登录面板。

It is working really fine but I do have a problem when I try to get the login panel with my smartphone. 它确实工作正常,但是当我尝试使用智能手机获取登录面板时,我确实遇到了问题。

I have this bit of javascript code: 我有这段JavaScript代码:

myAPI.js myAPI.js

function __getLoginPanel(developerapikey)
{
    var hostname = location.hostname;
    $.ajax({
        type: 'POST',
        data:{host:hostname, devkey:developerapikey},
        url: "http://www.example.com/loginPanel.php",
        success: function(htmlresponse) {
            $(".placeHolderLoginPanel").html(htmlresponse); 
        }   
    });
}

and my loginPanel.php looks like this (nothing special) 和我的loginPanel.php看起来像这样(没什么特别的)

loginPanel.php loginPanel.php

<form>
    <input type="hidden" name="devkey" value="<?php echo $_POST['devkey']; ?>">  
    <input type="text" id="username" name="username">
    <input type="password" id="passwort" name="passwort">
    <input type="button" name="loginSubmit" value="Login">
</form> 

When I call the API from another server like this: 当我从这样的另一台服务器调用API时:

my external php file which calls the API 我的外部php文件,该文件调用了API

<script src="http://www.example.com/myAPI.js"></script>
var developerapikey = "abc"; 
__getLoginPanel(developerapikey);

it only works in the browser. 它仅在浏览器中有效。 Very fast and nothing's wrong. 非常快,没错。

But when I call the website with my smart phone, nothing happens. 但是,当我使用智能手机拨打网站时,什么也没发生。

I've read something about 我读过一些关于

crossDomain: true 

in the ajax call, but nothing changes. 在ajax调用中,但没有任何变化。

Please help me out :-) 请帮帮我:-)

Thanks guys!! 多谢你们!!

Ok, everything is alright. 好的,一切都很好。 It was an error in the Origin Header in my php file. 这是我的php文件中Origin Header中的错误。

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

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