gpt4 book ai didi

php - xmlHttp 字符串 POST header 问题

转载 作者:行者123 更新时间:2023-11-30 06:08:49 32 4
gpt4 key购买 nike

我正在尝试通过 XmlHttp 方法传递一个字符串。让我向您展示代码:

HTML

<div id="greetings">
You are voting out <b style="color: #00b0de;" id=roadiename></b>. Care to explain why?<br/><br/>
<textarea name="textarea" id="comment" cols="38" rows="7"></textarea><br>
<a href="#" id="postmsg" onclick='getMsg("#comment.val()")' ><img src="images/submit.gif" style="border: none; float:right; padding-top: 10px;padding-right: 10px;"/></a>
</div>

JavaScript

function getMsg(msg)
{
msgBox = msg;
}

Core.addEventListener(submit, "click", function(){Slide.send();});

发送函数

send: function()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}

var url="user_submit.php",
data="vote="+value+"&sid="+Math.random();
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
xmlHttp.setRequestHeader("Content-length", data.length);
xmlHttp.open("POST",url,true);
xmlHttp.send( data );

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("greetings").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}
},

说完一切后,这是 Firebug 显示的错误:

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: http://localhost/roadies/JS/script.js :: anonymous :: line 96"  data: no]

Line 0

最佳答案

编辑:

你必须调用open;在你可以使用 setRequestHeaders 之前。


http://localhost/roadies/JS/script.js 的第 96 行实际上是什么?

关于php - xmlHttp 字符串 POST header 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1942665/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com