早上好!
我正在编写一个小型 AJAX 应用程序,使用此函数作为基础,并使用 php 作为服务端语言。
这是涉及的javascript代码
var dati = {};
dati.nome = d.getElementById('nome').value;
dati.cognome = d.getElementById('cognome').value;
console.log(dati);
url = "post.php";
jsonToPost = dati;
console.log(url);
processResponse = function(responseText){
console.log(responseText);
d.getElementById('response').innerHTML = responseText;
}
_SU3.postAjax(url, processResponse, jsonToPost);
});
这是我的php代码,只是一个测试ajax的后处理器
<?php
if(isset($_POST['nome'])){
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$data['nome'] = $nome;
$data['cognome'] = $cognome;
$data = json_encode($data);
echo $data;
} else {
echo "Errore!";
}
?>
我从 ajaxRequest 得到的响应是“Errore!”,这意味着它没有向脚本发布任何内容。
我错过了任何明显的错误吗?还是我做错了什么?
_SU3.ajax() 函数(见this for reference)工作得很好,所以我很惊讶它不起作用
---编辑广告萤火虫响应---我希望我发布了正确的东西
request headers:
POST /~francesco/post.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/2010010 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost/~francesco/ajax.html
Content-Length: 26
Pragma: no-cache
Cache-Control: no-cache
屏幕截图 中的屏幕截图还有其他信息。