XMLHTTPRequest method POST appears not to be sent

Discussion in 'Javascript' started by gp, Mar 6, 2007.

  1. gp

    gp Guest

    I have a an Ajax post sent to a php script on the server...the script
    returns a response indicating that the _POST array wasn't set.

    When I look at firebug, my headers appear to be ok, and the HTTP_POST
    appears intact and doesn't appear out of sorts. And the response from
    the PHP script is that of $_POST not being set.

    function reqCocktailDetails(clid, cktlid) {
    try {
    var url = "http://<URL HERE>/process_xhr.php";
    var str = "clid=" + clid + "&cktlid=" + cktlid;
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www=form-
    urlencoded");
    //http.setRequestHeader('Content-length', str.length);
    //http.setRequestHeader('Connection', 'close');
    http.onreadystatechange = hrGetDetails;
    http.send(str);
    } catch (err) {
    var errorSpan = document.createNode("span");
    $("divCktlPopUp_body").appendChild(errorSpan);
    var errorTxt = err;
    errorSpan.appendChild(errorTxt);
    }
    }

    function hrGetDetails() {
    if (http.readyState == 4) {
    var responseTxt = http.responseText;
    var respObj = eval("(" + responseTxt + ")");
    var thisParentID = "divCktlPopUp_body";
    if (!errorCheck(respObj, thisParentID)) {
    buildCktlAddMod(respObj);
    }
    }
    }
     
    gp, Mar 6, 2007
    #1
    1. Advertising

  2. gp

    gp Guest

    On 6 Mar, 09:36, "gp" <> wrote:
    > I have a an Ajax post sent to a php script on the server...the script
    > returns a response indicating that the _POST array wasn't set.
    >
    > When I look at firebug, my headers appear to be ok, and the HTTP_POST
    > appears intact and doesn't appear out of sorts. And the response from
    > the PHP script is that of $_POST not being set.
    >
    > function reqCocktailDetails(clid, cktlid) {
    > try {
    > var url = "http://<URL HERE>/process_xhr.php";
    > var str = "clid=" + clid + "&cktlid=" + cktlid;
    > http.open("POST", url, true);
    > http.setRequestHeader("Content-type", "application/x-www=form-urlencoded");
    > //http.setRequestHeader('Content-length', str.length);
    > //http.setRequestHeader('Connection', 'close');
    > http.onreadystatechange = hrGetDetails;
    > http.send(str);
    > } catch (err) {
    > var errorSpan = document.createNode("span");
    > $("divCktlPopUp_body").appendChild(errorSpan);
    > var errorTxt = err;
    > errorSpan.appendChild(errorTxt);
    > }
    >
    > }
    >
    > function hrGetDetails() {
    > if (http.readyState == 4) {
    > var responseTxt = http.responseText;
    > var respObj = eval("(" + responseTxt + ")");
    > var thisParentID = "divCktlPopUp_body";
    > if (!errorCheck(respObj, thisParentID)) {
    > buildCktlAddMod(respObj);
    > }
    > }
    >
    > }



    I found the error of my ways....the obnoxiously minute typo strikes
    again!!!
    > http.setRequestHeader("Content-type", "application/x-www=form-urlencoded");

    NOTE: the "=" in "application/x-www=form-urlencoded"

    REPLACE: with "-" to make it "application/x-www-form-urlencoded"
     
    gp, Mar 6, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dalton Barreto
    Replies:
    4
    Views:
    566
    Dalton Barreto
    Nov 7, 2006
  2. Ting Chang
    Replies:
    10
    Views:
    653
    7stud --
    Apr 30, 2011
  3. joe
    Replies:
    0
    Views:
    232
  4. Henri-Bastien

    POST a form with XmlHttpRequest

    Henri-Bastien, Mar 23, 2005, in forum: Javascript
    Replies:
    2
    Views:
    111
    Metaphis
    Mar 23, 2005
  5. HugeBob
    Replies:
    10
    Views:
    290
    HugeBob
    Apr 6, 2007
Loading...

Share This Page