如何调用使用Ajax PHP函数? [英] How to call a PHP function with Ajax?
本文介绍了如何调用使用Ajax PHP函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个PHP函数返回一个数组:
I have a PHP function which returns an array :
function lire( $id) {
$ret = array() ;
$sSQL = "SELECT * FROM produit WHERE prod_code = '$id' LIMIT 1" ;
$this->db->query($sSQL) ;
$ret['cnt'] = $this->db->num_rows() ;
return $ret;
}
我怎么能调用这个PHP函数中的Ajax?
How can I call this PHP function within Ajax ?
推荐答案
你必须把这个code块在一个PHP文件,将不得不调用它像AJAX功能:
You have to put this code block in a php file and will have to call it in the ajax function like:
var value = $.ajax({
type: "POST",
url: "some.php",
data: "name="+customvariable,
async: false
}).responseText;
也some.php文件将有
also the some.php file will have
if(isset($_POST['name']))
{
$id = mysql_real_escape_string($_POST['name']);
$ret = array() ;
$sSQL = "SELECT * FROM produit WHERE prod_code = '$id' LIMIT 1" ;
$this->db->query($sSQL) ;
$ret['cnt'] = $this->db->num_rows() ;
echo $ret;
}
您将获得的返回值在值变量。
You will get the return value in the value variable.
这篇关于如何调用使用Ajax PHP函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文