1

I am trying to build simple Search Bar but when I am trying to send data to PHP and for testing purposes. I am using ALERT it alerting whole HTML page content back again. I have Googled my problem couldn't find any thing.

My HTML CODE

    <?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>

MY PHP CODE

    <?php 

    echo 'testing';

?>

My Problem:

Image

3
  • Does your php.ini use the auto_prepend_file setting? Commented Mar 25, 2017 at 12:08
  • In your search.php file: Is there any code other than "echo 'testing';" ? Commented Mar 25, 2017 at 12:13
  • Give full path of link instead of '../' Commented Mar 25, 2017 at 12:20

1 Answer 1

1

You should use small letter for URL in ajax code

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

And I hope you know pass the data from ajax to php.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.