[英]Javascript Send GET Request
I am creating a script & I need it to be able to send a GET request. 我正在创建一个脚本,我需要它能够发送GET请求。 The only thing is, it will be a script that is entered into the Url bar into people's browsers.
唯一的是,它将是一个脚本,该脚本已输入到人们浏览器的“网址”栏中。 Below is the PHP code I have.
以下是我拥有的PHP代码。
<?php
$first = $_GET["first"];
$last = $_GET["last"];
$myFile = "names.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $first;
fwrite($fh, $stringData);
$stringData = ":";
fwrite($fh, $stringData);
$stringData = $last;
fwrite($fh, $stringData);
$stringData = "\r\n";
fwrite($fh, $stringData);
fclose($fh);
?>
I really need help. 我真的需要帮助 Thanks to everyone that helps me out.
感谢所有帮助我的人。
Something like this should work: 这样的事情应该起作用:
javascript:x=new XMLHttpRequest();x.open("GET", "//example.net/yourpage.php?fname=John&lname=Smith", true); x.send()
See the documentation on XMLHttpRequest . 请参阅XMLHttpRequest上的文档。
Basically, you just take the code you would have written in a Javascript block, and put it after the javascript:
URL scheme prefix. 基本上,您只需将要在Javascript块中编写的代码放在
javascript:
URL方案前缀之后。
You can try this 你可以试试这个
var fname="bily";
var lname="doc";
window.location.href = "phppage.php?first="+fname+"&last="+lname;
on php page you can use GET method to retrieve. 在php页面上,您可以使用GET方法进行检索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.