我有这个 AJAX
function getValFromDb() {
var university = document.getElementById('category').value;
var domain = document.getElementById('subcategory').value;
var year = document.getElementById('an').value;
var url = "modules/mod_data/tmpl/script.php";
var params = 'uni='+university+'&fac='+domain+'&an='+year;
if (window.XMLHttpRequest) { AJAX=new XMLHttpRequest(); } else { AJAX=new ActiveXObject("Microsoft.XMLHTTP"); }
if (AJAX)
{
AJAX.open("POST", url, false);
AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
AJAX.onreadystatechange = function()
{
if(AJAX.readyState == 4 && AJAX.status == 200)
{
document.getElementById('materie').innerHTML = AJAX.responseText;
}
};
} AJAX.send(params);
}
在这里发送参数
<?php
defined('_JEXEC') or die;
$db = JFactory::getDbo();
$an=$_POST('an');
$fac=$_POST('fac');
$uni=$_POST('uni');
$result1 =mysql_query("SELECT DISTINCT (materie) FROM drv_uni_$uni WHERE an='$an'");
while($row = mysql_fetch_array($result1)){
$display_string .= "<option value=\"".$row['id']."\">". $row['materie'] ."</option>";
}
echo $display_string;
?>
来自萤火虫的 POST
Parametersapplication/x-www-form-urlencoded
an an-3
fac Finante Banci
uni ase
Source
uni=ase&fac=Finante Banci&an=an-3
和标题
Response Headers
Connection keep-alive
Content-Encoding gzip
Content-Type text/html
Date Sun, 30 Dec 2012 13:12:47 GMT
Server xServers
Transfer-Encoding chunked
X-Powered-By PHP/5.3.16
请求标头
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
Content-Length 33
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie 0dea1a59adf779fae552e16f3d646b24=91481693c6b3c8615aa9ce57461aa590; 33a66e84ea7ae1332853383606d933e1=2039ee6737b4252207431790f5f7a939
DNT 1
Host www.domain.ro
Referer http://www.domain.ro/upload
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0
响应是空的!
Js 没有从 php 接收任何东西。PHP 已经正确地获取了这些值,但是当它发送时它不会返回给 js。如果您想向我展示如何使用 JSON 或修改此代码,我很感激。