为什么drupal_json
只返回页面 HTML?
这是代码:
PHP:
//Add js
function update_ajax_init(){
drupal_add_js("....");
}
//Function hook menu of me
function update_ajax_menu(){
$items = array();
$items['ajax/refresh'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'ajax_update_node',
'title' => 'Ajax update'
);
}
//Function main process return data json
function ajax_update_node(){
return drupal_json(array("flag"=>true));
}
Javascript:
$(document).ready(function(){
$("a.update_node").click(function(){
var params = {node_id: $(this).atrr("rel")};
$.ajax(
type: "POST",
url: "ajax/refresh",
data: params,
dataType: "json",
success: function(response){
if (response.flag == true){
alert("Success");
}
}
);
});
});
为什么响应值都是 HTML 代码而不是 json?{'flag'=>true}
来自 filefox 的回应:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
..................
..................