大家好,我正在使用 AJAX .post 运行 php 脚本,该脚本正在运行,但问题是从 .post 返回的调用返回整个 wordpress 页面,而不仅仅是我的脚本返回的数据。 就像 IM 调用脚本时再次加载页面一样。
这个 Ajax 调用在单帖子中被定位.php
$.ajax({ url: 'localhost/check/checkuser.php',
data: {action: window.myId},
type: 'post',
success: function(output) {
alert(output);
}
});
和用户查核.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页面加载用户查核.php文件时,它会将enture页面发回,我该怎么办?
领先 10 倍的家伙
有人建议:
- 对于数据库操作,请使用
global $wpdb
http://codex.wordpress.org/Class_Reference/wpdb - 您的脚本不受 sql 注入保护
- 对于WordPress中的ajax调用,我建议您使用WP具有的ajax脚本 http://codex.wordpress.org/AJAX_in_Plugins
- 制作一个(从这个简单的插件)http://codex.wordpress.org/Writing_a_Plugin
例:
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文件