duanpei8518 2015-09-14 02:51
浏览 264

Javascript发送GET请求

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 = "
";
fwrite($fh, $stringData);

fclose($fh);

?>

I really need help. Thanks to everyone that helps me out.

  • 写回答

2条回答 默认 最新

  • douxiong4892 2015-09-14 03:10
    关注

    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.

    评论

报告相同问题?