0

我在使用 jquery 在 php 中发送获取请求时遇到问题。它只是无法检测到获取值这里是我的代码:

 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();

        }

和我的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.
    }   
}
4

1 回答 1

0

如果您想在 JQuery 中执行此操作,它将如下所示:

查询:

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

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.
    }   
}
于 2013-11-05T21:35:33.727 回答