简体   繁体   English

ajax请求$ _get不起作用

[英]ajax request $_get not working

I'm having problems sending get request in php with jquery. 我在用jquery在php中发送get请求时遇到问题。 it just can't detect the get value here are my codes: 它只是无法检测到获取值,这是我的代码:

 function getopmerking($id) {
            document.getElementById("popup_box").style.display = "block";
            $httpreq = new XMLHttpRequest();
            $httpreq.onreadystatechange = function () {
                document.getElementById("txtouders").innerText = $httpreq.responseText;
                document.getElementById("requesteddata").innerText = $id;
            }

            $httpreq.open("GET", "files/request.php?q=1",true);
            $httpreq.send();

        }

and my php code: 和我的PHP代码:

    $id = $_GET["q"];
fetchData();
function fetchData()
{
    $drow = mysql_fetch_array(mysql_query("SELECT * FROM  `tblreservering` where fldllnid=$id;"));
    if(!empty($drow))
    {
        $drow['fldopmerking'];
    }else{
        echo "id is: ".$id."geen gegevens gevonden!"; 
        // i only get "id is: geen gegevens gevonden!" as output since $id is nothing.
    }   
}

If you wanted to do this in JQuery, it would look like this: 如果您想在JQuery中执行此操作,则将如下所示:

JQuery: jQuery的:

function getopmerking($id) {
  $("#popup_box").show();
  $.get("files/request.php?q=1", function(resp){
    $("#txttouders").text(resp);
    $("#requesteddata").text($id);
  });
}

PHP: PHP:

$id = $_GET["q"];
fetchData($id);
function fetchData($getId){
  $query = sprintf("SELECT * FROM  `tblreservering` where fldllnid=%d;", mysql_real_escape_string($getId));
    $drow = mysql_fetch_array(mysql_query($query));
    if(!empty($drow))
    {
        $drow['fldopmerking'];
    }else{
        echo "id is: ".$getId."geen gegevens gevonden!"; 
        // i only get "id is: geen gegevens gevonden!" as output since $id is nothing.
    }   
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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