Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  29] [ 3]  / answers: 1 / hits: 35091  / 11 Years ago, thu, october 3, 2013, 12:00:00

I would like to send 'ID' to JS function then send the same ID again from JS function to php function.
Please tell me what is the wrong in my code!



<script type=text/javascript>
function deleteclient(ID){ //I receive the ID correctly until now!
var x = <?php deleteclient11('ID');?>;
return false;
}
</script>

<?php
function deleteclient11($x)
{
echo $x;
}
?>

More From » php

 Answers
11

You need to use AJAX, it's easy with jQuery or another library, so I'll demonstrate with jQuery.



javascript



var deleteClient = function(id) {
$.ajax({
url: 'path/to/php/file',
type: 'POST',
data: {id:id},
success: function(data) {
console.log(data); // Inspect this in your console
}
});
};


php file



<?php

if (isset($_POST['id'])) {

deleteClient11($_POST['id']);

function deleteClient11($x) {
// your business logic
}

}

?>


More info: jQuery.ajax()


[#75270] Tuesday, October 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madilynndiannac

Total Points: 191
Total Questions: 93
Total Answers: 111

Location: France
Member since Thu, Oct 15, 2020
4 Years ago
;