jQuery ajax - 如何只在joomla组件返回时获取文本?

时间:2012-09-28 10:39:16

标签: jquery joomla

如何在使用jquery ajax时让joomla2.5组件只返回文本? 因为现在我得到了完整的HTML。我尝试添加“& format = raw”但不起作用! 如何解决?

的jQuery

$.ajax({
  type: "POST",
  url: "index.php?option=com_test&task=edit",

  ......................

2 个答案:

答案 0 :(得分:1)

当我需要输出一些JSON时,我通常不会让控制器进入视图。我将我想要的数据放入一个对象并将其传递给这个函数:

function jsonOut($obj) {
  $app = JFactory::getApplication();

  JResponse::setHeader( 'Expires', 'Mon, 1 Jan 2001 00:00:00 GMT', true );    // Expires in the past
  JResponse::setHeader( 'Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT', true ); // Always modified
  JResponse::setHeader( 'Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false );

  echo json_encode($obj);
  $app->close();
}

无需查看。它只是吐出JSON。

答案 1 :(得分:1)

你必须在任务结束时添加Jexit();你将摆脱完整的HTML。您也可以使用die(),但如果有Jexit()则为什么。欢呼声。

    function edit()
    {
     // Your code
     Jexit(); 
    }