我想通過ajax獲取一些數據,而且無論出於何種原因,我獲得了doctype,標題,元數據...以及我想要的數據。我想要的只是JSON數據。我使用Joomla 1.5jquery ajax返回doc類型和其他一些我不想要的東西
我的jQuery:
jQuery(document).ready(
function() {
jQuery('#catagoryChange').click(
function (event) {
event.preventDefault();
jQuery.getJSON("index.php?option=com_test&task=aJax&tmpl=component")
.success(function(data) {alert(data.myName); })
.error(function(data) {alert("error"); });
} // end of function event
); // end of click
} // end of function
); // end of document.ready
我的功能是想呼應只有JSON:
function testAxaj() {
$json = '
{
"myName": "Testing"
}
';
header('Content-type: application/json');
echo $json;
}
而這正是它返回
<!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" xml:lang="en-gb" lang="en-gb" dir="ltr" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="joomla, Joomla" />
<meta name="description" content="Joomla! - the dynamic portal engine and content management system" />
<meta name="generator" content="Joomla! 1.5 - Open Source Content Management" />
<title>Administration</title>
<link href="/Test/administrator/templates/khepri/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script type="text/javascript" src="/Test/includes/js/joomla.javascript.js"></script>
<script type="text/javascript" src="/Test/media/system/js/mootools.js"></script>
<link href="templates/khepri/css/general.css" rel="stylesheet" type="text/css" />
<link href="templates/khepri/css/component.css" rel="stylesheet" type="text/css" />
</head>
<body class="contentpane">
{
"myName": "Testing"
}
</body>
</html>
好吧,顯然它試圖返回HTML。服務器端代碼是什麼樣的?你可以做一個單獨的PHP頁面,只返回JSON? – tjameson 2011-04-20 05:29:12
我可以但我不想走這條路線,我正試圖堅持我的文檔流的其餘部分是MVC – milan 2011-04-20 12:44:12