Results 1 to 1 of 1

Thread: Troubleshooting POST transmissions to server

Threaded View

  1. #1
    Join Date
    Jun 2009

    Troubleshooting POST transmissions to server

    So I am setting up a rather simple web form-based database interface using AJAX. I have a Javascript constructor I call HttpPipe() [see code for it below]. It has the properties and methods you might expect.

    (i) Methods to define parameters for Xml HTTP Request object .open() method set up the URL, HTTP method (GET|POST|HEAD for now), and whether to be asynchronous.

    (ii) The .send() method gets called, and within that method, the Xml HTTP Request object gets constructed (by function outside HttpPipe() constructor)

    (iii) the HTTP response handler gets defined as a method in HttpPipe()

    (1) So I am doing a

    XmlHttpRequest.open("POST", "ajaxRecordsinterface.php", true);

    On the server side, I just want to see the raw POST data, and have it sent back to the client to be put into textarea content (which might later serve as a message window to user to wait for server side transaction). But I am not getting the raw POST data sent back. Just the leading text with time/datestamp. The source of the file ajaxRecordsInterface.php for trying to get raw POST data and echo it back as the HTTP response is also below.

    (2) In using the dependable Firebug, the Net panel reveals that I am getting a "302 Found" response, which passes on the "Location" header. The FF client was then sending a GET request, which I don't want, so I tried to insert handler code that re-packages a 302 response into the wanted method (POST request, in this case). The problem is, I have a Firebug breakpoint on the handler entry (see this.responseHandler() method), and it is showing a "200 OK" response.

    Anyone know why these things do not work as expected?

    // Javascript for a constructor--HttpPipe()--for AJAX interface
    function HttpPipe() {
       this.method = "GET";  // some defaults at construction
       this.isAsynchronousRequest = true;
       this.mimeType = "text/plain";
       this.url = null;
       this.requestObject = null;
       this.messageWin = null; // even though asynchronous
       this.setUrl = function (url) {
          if (typeof(url) == "string") {
             this.url = url;
             return true;
          return false;
       this.setMethod = function (methodSet) {
          if (typeof(methodSet) == "undefined")
             return false;
          methodSet = methodSet.toUpperCase();
          var approvedMethods = [ "GET", "POST", "HEAD" ];
          for (var i = 0; i < approvedMethods.length; i++)
             if (approvedMethods[i] == methodSet) {
                this.method = methodSet;
                 return true;
          return false;
       this.setMimeType = function (mimeType) {
          if (typeof(mimeType) == "undefined")
             return false;
          var approvedMimeTypes = [ "text/xml", "text/plain", "text/html" ];
          for (var i = 0; i < approvedMethods.length; i++)
             if (approvedMimeTypes[i] == mimeType) {
                this.mimeType = mimeType;
                return true;
          return false;
       var httpPipe = this; // for being able to put response handler in object
       this.sendData = function (formData, handler) {
          this.formData = formData;  // for non-200 responses!
          this.requestObject = XmlHttpRequestObject(); //  defined in 'ajax.js' to find right constructor
          if (this.requestObject.overrideMimeType)
          this.requestObject.onreadystatechange = function () {
          //  this.requestObject.open("POST", this.url, this.isAsynchronousRequest); // debugging code
          this.requestObject.open(this.method, this.url, this.isAsynchronousRequest); // to-be-final code
          this.requestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
          this.requestObject.setRequestHeader("Content-Length", this.formData.length);
          this.requestObject.setRequestHeader("Connection", "close");  // not sure about need for this ?
          this.messageWin = new userWaitMessage();  // may not need this in final version
          if (this.method == "GET")
          else if (this.method == "POST")
       this.responseHandler = function (reqObj) {
          if (reqObj.status == 302) { // Found response
             // re-package the data and use Location header for URL
             reqObj.open(httpPipe.method, reqObj.getResponseHeader("Location"),
             reqObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
             reqObj.setRequestHeader("Content-Length", httpPipe.formData.length);
             reqObj.setRequestHeader("Connection", "close");
          } else if (reqObj.readyState == COMPLETE) {
             for (var i = 0; i < httpResponseCodes.length; i++)
                if (reqObj.status == httpResponseCodes[i].code)
                if (i == httpResponseCodes.length) {
                   alert("Unknown HTTP Response! Code = " + reqObj.status);
            // most any valid HTTP response should be placed in the message window
             var msgPlace = httpPipe.messageWin.messageWin.document.getElementById("ajaxResponse");
             msgPlace.value = reqObj.responseText;

    PHP Code:
    // PHP file "ajaxRecordsInterface.php"
    /* header() and output buffering calls pulled off some other 
    forum post...willing to try anything at this point */
    header("Cache-Control: no-cache, must-revalidate");
    header("Content-Type: text/plain");
    header("Connection: close");
    echo "Here is what you POSTed at ".date("D j M Y H:i:s"time()).":";
    // in that forum post, readfile() was used, but was ineffective
    header("Content-length: ".ob_get_length());
    Last edited by mavigozler; 04-05-2010 at 02:18 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles