简体   繁体   English

javascript发布到.php文件一台服务器不起作用 - 在浏览器中手动输入URL到相同的.php工作

[英]javascript post to .php file one server does not work - manual entry of URL in browser to same .php works

i had some issues with understanding how to get javascript (client) variables transferred so they were acessible from php (serverside) as session : get an iframe's "src" value in PHP? 我有一些问题,了解如何转移javascript(客户端)变量,所以他们可以从PHP(服务器端)访问作为会话: 在PHP中获取iframe的“src”值?

Now im in a situation where i use firebug to try to debug whats going on, but it just doesnt make sense : 现在我处于一种情况,我使用firebug尝试调试正在进行的,但它只是没有意义:

i have this function to update an iframe and i want to pass on the page that that iframe is displaying : 我有这个功能来更新iframe,我想传递iframe正在显示的页面:

function frameclick(pageurl)
 {
        $.post("session_write.php?",
    {
            frameurl : pageurl             
    }

    $("#iFrame1").attr('src', pageurl);
    console.log  ('<?php echo "logout:".$langpath.$_SESSION['frameurl'];?>');
 }

pageurl is ex. pageurl是ex。 "/lang/en/new.htm" - and if i inspect it with firebug i also can see it says that it passes it correctly ( also with conversion of /). “/lang/en/new.htm” - 如果我用firebug检查它,我也可以看到它说它正确传递它(也转换为/)。

my script serverside that its posted to is like this : 我发布的脚本服务器端是这样的:

#session_write.php
<?php
session_start();
print_r($_GET['frameurl']);
if (isset($_GET['frameurl'])) 
{
$_SESSION['frameurl'] = $_GET['frameurl'];
print_r($_SESSION);
}
?>

Posting to that php script on the server will fail via the javascropt - $_SESSION['frameurl'] will be '', but if i ex. 发布到服务器上的PHP脚本将通过javascropt失败 - $ _SESSION ['frameurl']将是'',但如果我是ex。 do it manually like this : (http): 像这样手动执行:(http):

//localhost/phpmenu/session_write.php?frameurl=lang%2Fen%2Fnew.htm

then it will be correctly set in the $_SESSION["frameurl"] variable. 然后它将在$ _SESSION [“frameurl”]变量中正确设置。

I simply cannot understand whats different between doing the javascript post and doing it manually in the browser and why its causing me this problem ? 我简直无法理解在javascript帖子和在浏览器中手动执行它之间有什么不同以及为什么它会导致我这个问题?

anyone with an idea ? 有想法的人吗? thanks 谢谢

You are using .post , which executes a POST request, but when you type in the URL in the address bar, that is a GET request. 您正在使用.post执行POST请求,但是当您在地址栏中键入URL时,这是一个GET请求。

$_GET retrieves any params passed through GET, while $_POST retrieves any params passed through POST. $_GET检索通过GET传递的任何参数,而$_POST检索通过POST传递的任何参数。 So if you use .post with Javascript but try to retrieve with $_GET in PHP, it wouldn't work. 因此,如果您使用.post与Javascript但尝试使用PHP中的$_GET进行检索,则无效。

When you POST variables to a PHP file, $_GET is not set. 将变量POST到PHP文件时,未设置$_GET Use $_POST['frameurl'] instead. 请改用$_POST['frameurl'] Also, it looks like you're missing a close paren in frameclick to end the post call. 此外,看起来你在frameclick中错过了一个关闭frameclick来结束post调用。

You are passing data via a POST request and retrieving for all the GET requests. 您正在通过POST请求传递数据并检索所有GET请求。 Use $_POST instead. 请改用$_POST You may also be interested in $_REQUEST 您可能也对$_REQUEST感兴趣

暂无
暂无

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

相关问题 带有cURL的PHP​​脚本可在一台服务器上运行,而不能在另一台服务器上运行 - PHP Script with cURL works on one server…does not work on other server PHP / MySQL登录可在一台服务器(PHP 5.0.2)上运行,但不能在另一台服务器(PHP 5.1.6)上运行 - PHP/MySQL login works on one server (PHP 5.0.2) but does not work on the other (PHP 5.1.6) 使用php发送新帖子,但JavaScript不起作用 - Send a new post with php but JavaScript does not work 为什么相同的PHP UnityWebRequest在plesk服务器上不起作用,但在我的本地主机上起作用? - Why does the same php UnityWebRequest does not work on plesk server but works on my localhost? PHP和javascript无法将文件发布到远程服务器,而发布到本地服务器 - php and javascript can't post file to remote server while post to local server work 为什么 php 文件在 CLI 中有效,而在浏览器中无效? - Why does php file work in CLI but not in browser? 与PHP服务器的httpURLConnection给出不同的响应(URL在Web浏览器上有效) - httpURLConnection to php server gives different response (url works on web browser) 将javascript值传递给php并将其发布(相同文件) - passing javascript value to php and POST it (same file) php copy()可在ecplise CLI环境中使用,但不适用于Web浏览器 - php copy() works on ecplise CLI environment, but does not work with web browser PHP $ _POST不起作用 - PHP $_POST does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM