Javascript 正确的ajax post语法?
您好,我正在尝试将数据发布到数据库,它使用get,但不使用post 以下是我的javascript:Javascript 正确的ajax post语法?,javascript,ajax,Javascript,Ajax,您好,我正在尝试将数据发布到数据库,它使用get,但不使用post 以下是我的javascript: function updateShout(id) { var http = new XMLHttpRequest(); http.open("POST", location.href); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.send("ed
function updateShout(id)
{
var http = new XMLHttpRequest();
http.open("POST", location.href);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send("edit="+document.getElementById("EDITM").value+"&id="+id);
return false;
}
我正在使用index.php?edit=message&id=X向当前页面发出ajax请求
PHP运行得很好,但我相信它与这一行有关:
http.send("edit="+document.getElementById("EDITM").value+"&id="+id);
PHP(如果需要):
请关门。。找到了我的问题。我的名字而不是id是“EDITM”记住在你的数据上使用
window.encodeURIComponent
,我想这就是这个方法的用途:http.setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);您说“我正在使用以下命令向当前页面发出ajax请求:index.php?edit=message&id=X”。。。听起来您正在发送GET头文件,因此无法使用POST@woofmeow谁使用ie?hahaYes toencodeURIComponent
。如果您的数据有任何&个字符,您就完蛋了。
if($_SESSION['signedin'])
{
if(!is_blank($_REQUEST['edit'])) //if empty($value) && !is_numeric($value);
{
$id = toNum( $_REQUEST['id'] ); //if(!is_numeric($val)) return -1; return (int)$val;
$msg = htmlentities($_REQUEST['edit']); //secure dis
$query = $db->query("UPDATE shouts SET shout='$msg' WHERE shoutid='$id'");
$db->close();
exit;
}
}