Jump to content
xisto Community
Sign in to follow this  
cangor

Ajax Post Vs. Get arrrgh...

Recommended Posts

Mmkay, so what I'm doing is submitting some form data to a php script using AJAX. In AJAX, as you may or may not know, there's two methods of submitting data, post and get. "get" is what you see when a webpage ends in "get.php?variable=3478&value=fgf....." etc... whereas post data is hidden. Another main difference is that post can send much longer variables, whereas get is limited.

I'm working on something where I have to use post because I have some long strings that need to be sent. I can get everything working with my script using "get," but for some reason when I change it to post, the php script doesn't get the values of the variables. I'm assuming my error is in the php script, but I have no idea where, cause it's just a simple email script, and should just pick up the values of the submitted variables using the $_POST command. Does anybody have any ideas of why this may not be working?

The relevant part of my PHP code is just:

$to = $_POST['eaddress'];		$headers = 	'From: email@domain.com'. "\r\n" .				'Reply-To: email@domain.com'. "\r\n" .				'X-Mailer: PHP/' . phpversion();		$subject = $_POST['esubject'];		$message = htmlspecialchars($_POST['emessage'])."\n".$_POST['edata'];				if(mail($to, $subject, $message, $headers))		{			echo 'Email sent successfully!';		}		else {			echo "Error during message sending. Please try again.";		}

Thanks! ;)
Notice from rvalkass:

Merged 5 identical posts.

Share this post


Link to post
Share on other sites

Without scrutinising your PHP code in too much detail, and assuming that it worked well using $_GET originally, I suspect that your AJAX is actually a little off as the coding used for both methods is actually subtly different. Any chance we could have a peek at that too?One thing I should also point out is that it might be best to do some sort of validation/sanitation on the email address, as well as, say, the subject line and so on. Just for security reasons. ;)

Share this post


Link to post
Share on other sites

Looks just fine even though we can't tell too much since we can't see the FORM parameters from the page you're posting from. That would help to notice the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.