大家好我用AJAX .post运行php脚本,脚本正在运行,但问题是来自.post的返回调用返回整个wordpress页面,而不仅仅是我的脚本返回的数据。就像我在调用脚本时再次加载页面一样。
这个ajax调用在single-post.php中被调用
$.ajax({ url: 'localhost/check/checkuser.php',
data: {action: window.myId},
type: 'post',
success: function(output) {
alert(output);
}
});
和checkuser.php
$userid = $_POST['action'];
//$userid = 'zivvv';
$oMySQL = new MySQL();
$query = "Select share FROM videotable WHERE uid = '$userid'";
$oMySQL->ExecuteSQL($query);
$bb = $oMySQL->iRecords;
$aa = $oMySQL->aResult;
if ($bb == 0){
$query = "INSERT INTO videotable VALUES ('','$userid','true')";
$oMySQL->ExecuteSQL($query);
echo 'true';
return 'true';
}else{
$sharing = mysql_result($aa,0,"share");
echo $sharing;
return $sharing;
}
我是PHP的新手,从我看到的返回的调用,只返回“屏幕”上的所有内容,所以当wordpress页面加载checkuser.php文件时,它会返回enture页面,我该怎么办?关于它?
提前10倍球员答案 0 :(得分:1)
一些建议:
global $wpdb
http://codex.wordpress.org/Class_Reference/wpdb wp-content/plugins/userchecker.php
(您的档案)
<?php
/*
Plugin Name: user checker
Description: A brief description of the Plugin.
Version: 0.9
*/
//your code
?>
通过这种方式,您可以以良好的WP方式执行和激活自己的代码 所有内置的WP函数和类都将可用,因此您不需要包含任何WP文件