views:

188

answers:

2

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>

Javscript

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
A: 

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?

prodigitalson
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
amit
this is line 96.
amit
the exception is gone. no data still, though. i think i need a new user_submit.php file? or the SQL? i am going nuts.
amit
A: 

From the W3C spec, and Wikipedia, the HTTP headers are actually "Content-Type" and "Content-Length" (note the uppercase second word). Does changing the case make a difference?

Brian
did that. does not help.
amit
Case doesn't matter. From the HTTP 1.1 Spec Section 4.2 - "Field names are case-insensitive" - http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
Asaph
@Asaph: Thanks for clarifying
Brian