dtt27783 2009-12-21 21:13
浏览 37
已采纳

xmlHttp string POST Headers问题

i am trying to pass a string through the XmlHttp method. Let me show you the code:

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

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;
        }
    },

after everything is said and done, this is the error Firebug is showing:

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
  • 写回答

2条回答 默认 最新

  • dongwh1992 2009-12-21 21:29
    关注

    EDIT:

    You have to call open; before you can use the setRequestHeaders.


    What is actually on line 96 of http://localhost/roadies/JS/script.js?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像