Jump to content


Photo

Problem with send post function on IE


  • Please log in to reply
6 replies to this topic

#1 123tomek

123tomek

    GMC Member

  • New Member
  • 12 posts

Posted 01 December 2011 - 12:49 PM

What is wrong with function send_post.

function send_post(url, params) {
  var http = new XMLHttpRequest();
  http.open("POST", url, true);
  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  http.onreadystatechange = function() {//Call a function when the state changes.
       if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);
       }
  }
  http.send(params);
  return http.responseText;
}

In most recent browsers (Opera, FireFox and Chrome) it works fine but on IE 9.x not exactly. When I use this function to all data is sent correctly to the php file. I can save the php file-level variables to a file uploaded highscore but GM does not receive feedback and all the time waiting for the execution of subsequent commands. This is only for IE, other browsers are working properly.
  • 0

#2 turrule

turrule

    GMC Member

  • New Member
  • 22 posts
  • Version:GM:HTML5

Posted 01 December 2011 - 11:32 PM

I believe that IE and the other browsers require separate commands.

----
if (window.XMLHttpRequest) {
xmlObject = new XMLHttpRequest();
} else {
xmlObject = new ActiveXObject("Microsoft.XMLHTTP");
}


xmlObject.open("GET",url,async);
xmlObject.send(null);

return xmlObject.responseText;
----

I'm not sure if this will help, but hopefully it will.

*This code has a slightly different use than yours, but the main points are the "if" and "else" areas.

Edited by turrule, 01 December 2011 - 11:33 PM.

  • 0

#3 Pedrogabriel

Pedrogabriel

    GMC Member

  • New Member
  • 9 posts

Posted 09 December 2011 - 08:07 PM

Hello, I was testing something like this and does not work, I came here to check if someone already asked something like and found this thread.

It won't work here, but WHY? theres no problem in the code... (I know it cannot work in old IE)

function POST(argument0, argument1) {
  var http = new XMLHttpRequest();
  http.open("POST", argument0, true);
  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  http.onreadystatechange = function() {//Call a function when the state changes.
       if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);
	    return http.responseText;
       }
  }
  http.send(argument1);
}
(Komodo tip: "anonymous function does not always return a value")

I setup the extension in gm, press RUN and when it should run the loading screen stay loading forever, theres no debug where really debug error in gm so, it's a bit harder to know what the problem...
AND when i run any game, the nginx won't works correctly, the loaded IP points to a non existing page always in any browser.

In my test I would pass argument0 as "http://localhost/jst.php" Wamp server installed here.
and argument1 as "" just for testing purpose.

Always I've to build -> go to my updated script -> copy -> go to generated folder -> past
When I reach the temp folder theres a 0kb file...so I replace it to work.

Also, I need to copy the temp folder index path to try it on my browser (nginx problem)
And finally, the "Social:GM" (facebook + GM) Won't work here too, stay loading forever...
I don't know what is the real problem, but I think GM:HTML has bug a lot.

Edited by Pedrogabriel, 09 December 2011 - 08:31 PM.

  • 0

#4 Artaex Media

Artaex Media

    Artaex Media

  • GMC Member
  • 1531 posts
  • Version:Unknown

Posted 14 December 2011 - 02:01 PM

You can always do a normal GET-request, and do the POST request with PHP.

Also, you could use jQuery to get access to the ajax() function.
Which also has support for POST requests :)

Example:
$(document).ready(function () {
    $.ajax({
        url: "",
        type: "POST",
        success: function (reponse) {
            alert(response);
        }
    });
});

Edited by Artaex Media, 14 December 2011 - 02:03 PM.

  • 0

#5

  • Guests

Posted 14 December 2011 - 07:15 PM

Watch out for cross domain stuff. IE has issues doing cross-domain requests.

#6 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 14 December 2011 - 08:32 PM

http.open("POST", url, true);

... you're using asynchronized, yet treating it somewhat as synchronized.


function send_post(url, params) {
  var http = new XMLHttpRequest();
  http.open("POST", url, true);
  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  http.onreadystatechange = function() {//Call a function when the state changes.
       if(http.readyState == 4 && http.status == 200) {
            alert(http.responseText);
       }
  }
  http.send(params);
  /*
    At this point you are starting to send the data, however at this point, the data hasn't finished sending.
Therefore the server hasn't responded. Therefore http.responseText doesn't exist.
  */
  return http.responseText;
}

try:

function send_post(url, params) {
  var http = new XMLHttpRequest();
  http.open("POST", url, false);
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  http.send(params);
  if(http.readyState == 4 && http.status == 200) {
	return http.responseText;
  } else {
	return "Error";
  } 
}

Edited by Schalk, 14 December 2011 - 08:36 PM.

  • 0

#7 123tomek

123tomek

    GMC Member

  • New Member
  • 12 posts

Posted 11 March 2012 - 10:41 PM

http.open("POST", url, true);

... you're using asynchronized, yet treating it somewhat as synchronized.

try:

function send_post(url, params) {
  var http = new XMLHttpRequest();
  http.open("POST", url, false);
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");
  http.send(params);
  if(http.readyState == 4 && http.status == 200) {
	return http.responseText;
  } else {
	return "Error";
  } 
}



Yes. This is it. It works fine. Thank you :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users