简体   繁体   中英

How do i use Href but not get redirected? using HTML

SO basically I want to send a value using Href from Maintenance.html to another page called delete.php so I am fetching the values from the table and sending it to Delete.php using $("#tddd").append("<td><a href='delete.php?grievance_number="+field.grievance_number+"'>Delete</a></td>");

This is my table in maintenance.HTML page

<script>
$(document).ready(function(){


         $.getJSON("http://192.169.245.144/grievance_app/v1/view/default", function(result){
             $.each(result, function(i, field){
               $("#tddd").append("<tr>");
                 $("#tddd").append("<td>"+field.grievance_number+ "</td>");
                 $("#tddd").append("<td>"+field.customer_name+"</td>");
                  $("#tddd").append("<td>"+field.subject+ "</td>");

                   $("#tddd").append("<td>"+field.description+"</td>");
                   $("#tddd").append("<td>"+field.email+"</td>");
                   $("#tddd").append("<td>"+field.phone_number+ "</td>");
                    <!--$("#tddd").append("<td>"+field.status+ "</td>");
                // $("#tddd").append("<td>"+field.number + "</td>");
                 $("#tddd").append("<td><a href='delete.php?grievance_number="+field.grievance_number+"'>Delete</a></td>");
                 $("#tddd").append("</tr>");
                    console.log(field.grievance_number);
            });
                console.log(result);
         });


});

</script>   

and this is my delete.php

<?php
if(isset($_GET['grievance_number'])) {




    $service_url= "http://192.169.245.144/grievance_app/v1/update/default";

    $curl = curl_init($service_url);

    $grievance_number = $_GET['grievance_number'];



    $curl_post_data = array(
    "grievance_number" => $grievance_number,
    "status" => "Closed"

    );
    curl_setopt($curl, CURLOPT_URL, $service_url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curl);

    echo "this is the $grievance_number";
    if ($response === false) {
    $info = curl_getinfo($curl);
    curl_close($curl);
    die('error occured during curl exec. Additioanl info: ' . var_export($info));

}
curl_close($curl);

$decoded = json_decode($response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
    die('error occured: ' . $decoded->response->errormessage);

    }
echo 'response ok!';


    }

    ?>

instead of redirecting the page I would just want it to send the data using href and refresh the current HTML page instead, or a popup saying success, don't want to redirect. Thanks for your help.

href is meant to take you to the new page

If you want to delete anything and you don't want to move to any other page, you need to use Ajax . Learn about Ajax and you will be good to go.

You can use ajax to send data to the server without page refresh. You can do something like this

jQuery.ajax({
    url: "delete.php?grievance_number="+field.grievance_number+"",
    type: 'DELETE',
    success: function(data) {
        show_items();
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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