是否可以使用 JavaScript var i= [[“j.php?i=”+input]];发送到 PHP
is it possible to use javascript var i= [["j.php?i="+input]]; to send to php?
我是新手,只是在做我刚刚做的练习: var i= [["j.php?i=1"]];
,它将值发送到php并打印,但是当我想要用户的一些输入时,它什么也不做。例如:
文件 J.js
var input = "hello";
var send= [["j.php?i="+input]];
在 j.php
<?php
$e=$_GET['i'];
echo $e;
?>
任何想法或我完全错了?我试图有一些变化。我真的对window.location.href
做到了.但我只是想知道如何以这种方式做 var send= [[]]。谢谢
编辑:你的问题不是很清楚,也许试试这个:
var input = "hello";
var url = "/j.php?i=" + input;
var send = [[url]];
但是,我不清楚你想用你的send
变量做什么......
源语言
您必须使用标记(GET方法(,表单(POST方法(或Ajax请求(任何Http动词(将数据发送到服务器:
<!-- Here you give a unique id to your link -->
<a id="link" href="">your link</a>
<script>
var i = "Hello";
// wait for page to be loaded
document.addEventListener("DOMContentLoaded", function(event) {
// change the href attribute of the link with the id equal to 'link'
// with whatever data contained in the i variable
// this is done after the page is loaded
document.getElementById("link").href = "/j.php?i=" + i;
});
</script>
然后,当您单击链接时,它会将名为 i
的变量发送到您的 php 页面,其中包含Hello
的值。
您也可以通过以下方式执行此操作:
<a id="link2">your link</a>
<script>
var i = "HELLO";
// wait for page to be loaded
document.addEventListener("DOMContentLoaded", function(event) {
// here we are telling javascript to change the url
// in the browser when the user clicks the link
document.getElementById('link2').onclick = function() {
window.location = '/j.php?i=' + i
}
});
</script>
相关文章:
- 使用php或javascript从facebook相册URL中删除多余的部分
- 将PHP变量传递给jQuery时遇到问题
- 通过javascript重定向html传递php变量
- 将数组从PHP传递到Javascript
- 如何在php文件中获取$.post-ajax传递的值
- Javascript运行php文件,然后下载文件
- PHP中的setcookie仅适用于localhost
- 如何使用jquery处理php循环通过元素
- 通过Ajax将JavaScript函数传递给PHP文件
- 而循环只设置php中输入字段中的第一个值
- 我需要从php调用javascript或jquery
- 如何通过php页面将数据库值检索到jquery自动完成框中
- PHP AJAX图片上传示例不上传
- 是否可以使用 JavaScript var i= [[“j.php?i=”+input]];发送到 PHP
- 什么是“;php://input"意思是
- file_get_contents('php://input'); with application/x
- 我如何从php中获取一个值,并通过javascript将其放入input-element中
- 在包含的form.PHP中添加一个input's值
- & lt; input>使用AJAX调用PHP函数
- jQuery从PHP控制器发送值的问题$this->input->post('id', TRUE);.