I want to post textarea data to a php form and get its response back to another textarea. could you guys tell me how this can be done? I tried following but it doesn’t work!
$.post(url, dataToBeSent, function(data, textStatus) {
url="./doit.php";
var dataToBeSent = $("myform").serialize();
var siteContents2 = data.contents;
document.myform2.outputtext2.value = siteContents2 ;
}, "json");
forms:
<form id="myform" name="myform" action="./ok1.php?Id=&title=" method="post">
<td><textarea rows="7" cols="15" name="outputtext" style="width: 99%;"></textarea></td>
</form>
<form id="myform2" name="myform2" action="./ok2.php?Id=&title=" method="post">
<td><textarea rows="7" cols="15" name="outputtext2" style="width: 99%;"></textarea></td>
</form>
php get data passed beg getjson:
$passed3 = $_post['dataToBeSent'];
echo $passed3;
You define the URL and data in the callback function. You need to define them before you call
$.post(). You can try it with the code below, this is the ‘shorthand‘ version with$.ajax().JS
PHP
More information about POST-requests with jQuery: http://api.jquery.com/jQuery.post/