我想发送'ID'到JS函数然后再从JS函数发送相同的ID到PHP函数.请告诉我我的代码有什么问题!
<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";
}
?>
Run Code Online (Sandbox Code Playgroud)
你需要使用AJAX,使用jQuery或其他库很容易,所以我将用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
}
});
};
Run Code Online (Sandbox Code Playgroud)
php文件
<?php
if (isset($_POST['id'])) {
deleteClient11($_POST['id']);
function deleteClient11($x) {
// your business logic
}
}
?>
Run Code Online (Sandbox Code Playgroud)
更多信息:jQuery.ajax()
| 归档时间: |
|
| 查看次数: |
23099 次 |
| 最近记录: |