user2724175
user2724175

Reputation: 39

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.

Upvotes: 1

Views: 2539

Answers (2)

Barmar
Barmar

Reputation: 780984

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.

Upvotes: 1

Gautam
Gautam

Reputation: 1056

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.

Upvotes: 0

Related Questions