php - Why is drupal_json only returning page HTML? -


why drupal_json returning page html?

here's code:

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");                }            }         );     }); }); 

why response value html code , not json? {'flag'=>true}

response 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" /> .................. .................. 

your question looks similar how can return actual json using drupal?

it looks you're going use auto-complete function. either way you're function ajax_update_node should this. rename function looks you're implementing hook. it's similar hook_nodeapi.

function ajax_update_node() {     $result = array('flag' => true);     drupal_json($result);     exit; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -