ajax jquery php提交

我在php中有一个简单的表单,它有一个用户文本框和pass文本框,我们称之为login.php。 我有另一个php页面,我们称之为sendtologin.php,我想通过jquery ajax'发送'凭据发布到login.php。 login.php在server1上,sendtologin.php在server2上。 当我尝试加载sendtologin.php时,我得到状态代码0和错误。 这是我的脚本。</ p>

  $(document).ready(function(){
$ .ajax({
type:“POST”,
url:“ http://server1/login.cgi“,
data:{lang_changed:”no“,用户名:”me“,密码:”me“},
成功:function(data){alert(”success!“ );},
错误:function(request,type,errorThrown){
alert(“request:”+ request.status +

requestText:”+ request.statusText +

Type:”+ type +

Exception:”+ errorThrown);}
});
});
</ code> </ pre>

我做错了什么?</ p >
</ div>

展开原文

原文

i have a simple form in php that has a user textbox and pass textbox we'll call it login.php. I have another php page, let's call it sendtologin.php, that i want to 'send' the credentials via jquery ajax to post to login.php. The login.php is on server1 and sendtologin.php is on server2. when i try to load the sendtologin.php i get a status code of 0 and error. here is my script.

$(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "http://server1/login.cgi",
            data: { lang_changed: "no", username: "me", password: "me" },
            success: function (data) { alert("success!"); },
            error: function (request, type, errorThrown) {
                alert("request: " + request.status + 
                      "
requestText: " + request.statusText +
                      "
Type: " + type + 
                      "
Exception: " + errorThrown); }
        });
    });

what am i doing wrong?

douquan2023
douquan2023 stackoverflow.com/questions/1201429/...如果没有JSONP或代理,您无法跨浏览器请求
大约 8 年之前 回复
dongling4288
dongling4288 en.wikipedia.org/wiki/Same_origin_policy
大约 8 年之前 回复

2个回答



您最好的办法是将登录凭据传递到“login.php”(如果它与您的ajax调用位于同一服务器上) 然后使用PHP的cURL函数将发布的变量传递给你的第二个域的“login2.php”。</ p>

我使用这个网关/直通技术ALOT,它适用于绕过那些讨厌的交叉 域政策问题。</ p>
</ div>

展开原文

原文

Your best bet is to pass the login credentials into your "login.php" (if its on the same server as your ajax call) and then use PHP's cURL function to pass the posted variables to your second domain's "login2.php".

I use this gateway / passthrough technique ALOT and it works for getting around those pesky cross-domain-policy issues.



我也遇到了这个问题,问题是Ajax调用的目的是出于安全原因在单个服务器上工作, 因此,当您将呼叫发送到其他服务器时,您将无法收到答案,因此“成功”方法将无效。 这并不意味着server1没有收到数据,但你无法验证它是否正确。</ p>

如果您有登录信息,则可以使用备用解决方案。 在server1上的数据库,您可以使用php连接到数据库并授予对原始服务器的访问权限,然后您可以基于该数据库连接进行所有ajax调用。</ p>
</ div>

展开原文

原文

I bump into this problem also, the thing is that the purpose of the Ajax call is to work on a single server for security reasons, so when you are sending the call to the other server you won't receive an answer, therefore the "success" method won't work. This doesn't mean that server1 didn't receive the data though, but you can't validate if it was correct.

An alternate solution would be, if you have the login information on a database on server1, you can use php to connect to the database and grant access to your origin server, and then you can make all your ajax calls base on that database connection.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问