gpt4 book ai didi

javascript - 表单数据在新页面中不可见 - PHP + Javascript

转载 作者:行者123 更新时间:2023-12-02 17:37:15 25 4
gpt4 key购买 nike

我有一个包含一组超链接的页面。单击任何超链接都会将用户带到一个新页面,其中 URL 作为 POST 数据发送。

我能做什么:
1. 打开新页面。

我面临的问题:
1. 在新页面中,我尝试访问作为数据发送的 url。网址不可见。我哪里出错了?

到目前为止我拥有的代码:

<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function takeMeHome(obj) {
var URL = obj.getAttribute("href");
//alert("Url = " + URL + " with id = " + obj.id);
console.log("URL = " + URL);
$.ajax({
type: 'POST',
url: './bbCloud.php',
data: {'tgt_url': URL},
success:function(data) {
console.log("Function invoked. It seems posting data was a success");
window.location = URL;
//alert('This was sent back: ' + data);
}
});
return false;
}
</script>
</head>
<body>
<p>
Choose one of the links below to access content:</p>
<p><a href="./bbCloud.php" id="link1" onclick="takeMeHome(this); return false;">1. Email Etiquette</a></p>
</body>
</html>

bbCloud.php:

<?php
//the function below displays data from bbMainPage javascript.
function getDataFromLibrary() {

$tgt_url = $_POST["tgt_url"];
echo "Data received = " . $tgt_url . "<br/>";
return $tgt_url;
}

?>

<html>
<head>
<style>
.hlight{background-color:#ffcc00;}
textarea {
width:100%;
height:100%;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://myDomain/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">

//mention all global variables here.
console.log("this is the start of javascript");
//get all data from the previous script.
var tgtURL = "<?php getDataFromLibrary(); ?>";
console.log("URl obtained = " + tgtURL);
</script>

<body>
<div>
<audio id="playText" src="" controls></audio>
</div>
</body>
</html>

最佳答案

尝试动态创建并提交表单,而不是尝试使用ajax itp>

    <script type="text/javascript">
function takeMeHome(obj) {
var URL = obj.getAttribute("href");
$('<form>', {
"html": '<input type="text" name="tgt_url" value="' + URL + '" />',
"action": URL
}).appendTo(document.body).submit();
}
</script>

关于javascript - 表单数据在新页面中不可见 - PHP + Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22515813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com