Jump to content

MyHttpRequest.open("POST", file, true) NOT WORKING


limitphp

Recommended Posts

Its loading the correct page in the correct target_div, but the form data is not being sent.  Can someone help me?

 

Here's my code:

<form name='frmInbox$messageID' method='post' action='myaccount_ajx_inbox_reply.php' onsubmit='return false'>
<input type='hidden' name='to_userID' value='$to_userID'>
<textarea NAME='message' style='overflow-x: hidden; display: block;' cols='65' rows='10'></textarea>
</textarea>
<input type='submit' value='Submit' onclick='check_message($messageID)'>
</form>	

 

here's check_message():

function check_message(messageID){
ajx_post('message'+messageID, 'myaccount_ajx_inbox_reply.php', '');

}

 

here's my ajx function:

function ajx_post(target_div, file, params)
{
var MyHttpRequest = false;
if (target_div.indexOf("voteCount")>=0)
var MyHttpLoading = '';
else
var MyHttpLoading = '<p>Loading...</p>'; // or use an animated gif instead: var MyHttpLoading = '<img src="loading.gif" border="0" alt="running" />';

var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, try firefox or internet explorer instead.';

if(window.XMLHttpRequest) // client use Firefox, Opera etc - Non Microsoft product
{
try
{
	MyHttpRequest = new XMLHttpRequest();
}
catch(e)
{
	MyHttpRequest = false;
}
}
else if(window.ActiveXObject) // client use Internet Explorer
{
try
{
	MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
	try
	{
	MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
	MyHttpRequest = false;
	}
}
}
else
{
MyHttpRequest = false;
}

if(MyHttpRequest) // browser supports httprequest
{
var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching
var query_string = url_encode('?rand=' + random + params);

MyHttpRequest.open("POST", file, true); // <-- run the httprequest using GET
//Send the proper header information along with the request
MyHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
MyHttpRequest.setRequestHeader("Content-length", query_string.length);
MyHttpRequest.setRequestHeader("Connection", "close");

// handle the httprequest
MyHttpRequest.onreadystatechange = function ()
{
	if(MyHttpRequest.readyState == 4) // done and responded
	{
		document.getElementById(target_div).innerHTML = MyHttpRequest.responseText; // display result
	}
	else
	{
		document.getElementById(target_div).innerHTML = MyHttpLoading; // still working
	}
}
MyHttpRequest.send(query_string);
}
else
{
document.getElementById(target_div).innerHTML = ErrorMSG; // the browser was unable to create a httprequest
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.