Ajax 返回页面 Html 代码返回(相同代码)

塔林达机场

我正在尝试构建简单的搜索栏,但是当我尝试将数据发送到 PHP 并用于测试目的时。我正在使用 ALERT 它再次提醒整个 HTML 页面内容。我用谷歌搜索我的问题找不到任何东西。

我的 HTML 代码

    <?php
require "../imports/productconnection.php";

if(!isset($_SESSION['adminname']) ){
    header('Location:../ad');
}else{

?>
<!DOCTYPE html>
<html>
<title>Viwe New Orders</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3.css">
<body>

<?php  require "./nav/nav.php";?>
<br><br>
<input type="radio" onclick="wichselect()" name="searchtype" checked="checked" id="name" value="name"> Full name
<input type="radio" onclick="wichselect()" name="searchtype"  id="id" value="id"> Id/Passport
<input type="radio" onclick="wichselect()" name="searchtype" id="tele" value="Phone"> Phone number

<form class="w3-container">
  <p>
  <h3><label id="searchBy"></label></h3>
  <input onkeyup="search()" class="w3-input" placeholder="Search" type="text"></p>
  </form>


<div id="result"></div>  
</body>
</html>
<?php }?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
wichselect();

    function wichselect(){
        var selected;
        if(document.getElementById('name').checked==true){
          selected = document.getElementById('name').value;

        }else if(document.getElementById('id').checked==true){
            selected = document.getElementById('id').value;
        }
        else{
            selected = document.getElementById('tele').value;
        }
        document.getElementById('searchBy').innerHTML = "Seachc Customer By " + selected;
    }

function search(){
    var selected;
        if(document.getElementById('name').checked==true){
          selected = document.getElementById('name').value;

        }else if(document.getElementById('id').checked==true){
            selected = document.getElementById('id').value;
        }
        else{
            selected = document.getElementById('tele').value;
        }
    alert(selected);
    var link = '../order_admin/search.php?item='+selected;
    alert(link);
$(document).ready(function(){
  $.ajax({
    type:'GET',
    URL:link,
    success:function(datacame){
      alert(datacame);
    }


  });

});

}

</script>

我的 PHP 代码

    <?php 

    echo 'testing';

?>

我的问题:

图像

戈帕拉克里希南

您应该在 ajax 代码中使用小写字母作为 URL

$.ajax({
type:'GET',
url:link, //HERE You to change
success:function(datacame){
  alert(datacame);
}
});

我希望你知道将数据从 ajax 传递到 php。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章