这是我的ajax脚本
<script>
$(document).ready(function()
{
$("#color-submit").click(function()
{
$.ajax(
{
async:false,
type:"POST",
url:"<?php echo plugins_url(\'/query/colorsubmit.php\',__FILE__);?>",
data:$("#color-form").serialize(),
dataType:\'json\',
success:function(response)
{
alert(response.msg);//var object = JSON.parse(response);
$(".jumbotron").css({"background-color":"#FF8745"});
//alert(response[\'msg\']);
var obj=response.msg;
console.log(obj);
}
}
);
});
});
</script>
这是我在WordPress中的ajax操作页面:<?php
$return = array();
//include_once("../../../../wp-config.php");
global $wpdb;
$color_value=$_POST[\'color-field\'];
if($wpdb->query("UPDATE color_form SET color=\'$color_value\'"))
{
$msg="Form Updated";
}else
{
$msg="not form Updated";
}
//$fetch_color=$wpdb->get_results("select color from color_form",ARRAY_A);
//$return=$fetch_color;
$return[\'msg\']="sdgsdgsd";
echo json_encode($return);
// wp_send_json_success($return);
//wp_send_json($return);
//$wpdb->flush();
?>
那么,我应该如何从ajax操作页面获取数据呢?如果我使用wp-config.php
我无法获取数据。如果我不使用它,我将无法运行查询。。。。。。。