简体   繁体   中英

Javascript Send GET Request

I am creating a script & I need it to be able to send a GET request. 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

$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 .

Basically, you just take the code you would have written in a Javascript block, and put it after the javascript: URL scheme prefix.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM