0

How to send ANY text via jquery ajax method to php script?

When text entered in textarea is html entity, php $_POST[]/$_GET[] sees it as empty string.

Here is the code:

<head>
	<script type="text/javascript" src="/Engine/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("button").click(function(){
				$.ajax({
					type: "GET",
					url: "get.php",
					data: "ta=" + $("#ta").val(),
					success: function(data){
						alert(data);
					}
				});
			});
		});
	</script>
</head>

<body>
		<textarea id="ta"></textarea>
		<button>Send it</button>
</body>

and the get.php:

<?php
	echo $_GET['ta'];
?>

type in textarea "&lt;b&gt;dog&lt;/b&gt;", press the button and empty string will be alerted. Why and how to fix it so that every text will be successfuly delivered to php script?

Thnx in advance

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by McLaren
0

Hey, I've got it. Actually it is very strange, but the problem was

data: "ta=" + $("#ta").val()

in this way when you input in textarea "&lt;b&gt;dog&lt;/b&gt;" it alerts nothing.

However when I use

data: {ta: $("#ta").val()}

everythings works fine! :]

Thnx!

0

cool :) I was lazy to try with get, because I tried on codeigniter framework, and in it if you want $_get, you have to configure something :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.