1

i'm working on a a website and i've made a php file that will show my search results, (i'm working on request appointment) so when i click that it works but the only problem is my webpage refresh and it shows a blank page until i click on home button to redirect

// my research loop...

if(isset($_GET['submit-search'])) {
    $search = mysqli_real_escape_string($conn, $_GET['search']);
    $sql = "SELECT * FROM doctor WHERE DoctorFullName LIKE '%$search%' OR DoctorLocation LIKE '%$search%' OR DoctorSpeciality LIKE '%$search%'";
    $result = mysqli_query($conn, $sql);
    $queryResult = mysqli_num_rows($result);
        if ($queryResult > 0) {
?>
<div class="container overflow">
<div class="container overflow">
    <span class="mentor">
        <h2 class="display Text-mentor">
            <span class="mentor-admin">If the result shown bellow not seems like what you need then ;</span>
            <span class="mentor-admin-quote">select the speciality of the doctor you need and your insurance, and <span class="turquoise">search</span> again</span>
        </h2>
    </span>
</div>
<div class="container overflow">
    <p class="p-about-results"><?php echo "There is ".$queryResult." result matching your search"?></p>
    <p class="p-about-results">we hope that these results are the ones you are looking for :</p>
</div>
<?php
    while ($row = mysqli_fetch_assoc($result)) :
?>

// my calendar for so i can submit appointment

<div id="myModal" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
        <span class="close">&times;</span>
        <form>
            <input type="text" name="ap-time" id="t1" class="modal-input-text" placeholder="Choose a date">
            <div id="sub" style="top: 40px;left: 5px;z-index:1;text-align: center;"></div>
            <input type=submit name="ap_validation" value="request appointment" class="input-requestdate">
        </form>
    </div>
</div>

//Ajax code that i've been working on

<script type="text/javascript">
$(document).ready(function(){

    //alert("jquery is working");
    $(".input-requestdate").click(function(){
        var name = $(".modal-input-text").val();
        $.ajax({
            url: "Appointment.php",
            type: "POST",
            async: false,
            data: {
                "done": 1,
                "message": name,
            },
            success: function(data){

                alert("requested");
                window.location = window.location.href
            }
        })

    });

});
</script>`

thanks for helping :)

Johannes
  • 53,485
  • 15
  • 52
  • 104
  • 2
    Well you have `window.location = window.location.href` in your success callback... If you refresh the page through JavaScript, it won't have the response from your AJAX any more. – Obsidian Age Feb 19 '18 at 01:03
  • Blank page can be cause by an internal PHP error. Have you check the error log for clue? See https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display and welcome to SO – Louis Loudog Trottier Feb 19 '18 at 01:08
  • 1
    @LouisLoudogTrottier i don't think php is the probleme here i just think i miss something here when i submit appointment i should like add something that will not refresh the page so all the records will still be in the page – Hamza Yahiaoui Feb 19 '18 at 01:11
  • If you are submiting your form with ajax aren't you suppose to have somethine like `preventDefault` or `return false` .Also i've notice that `alert()` can break ajax callback because it waits for the user input and by the time you click 'ok' it's too late. I was bypassing this using `console.log()` instead. ** I say all this form old time memories from about 5 years ago, might (probably) have change since then. best regards. – Louis Loudog Trottier Feb 19 '18 at 01:24
  • how about remove `async: false` from your ajax option !!! – David Jaw Hpan Feb 19 '18 at 02:10

0 Answers0