I'm trying to complete some ajax requests to insert a textarea into a database without refresh. Here is my code:
HTML:
<textarea name='Status'> </textarea>
<input type='button' onclick='UpdateStatus()' value='Status Update'>
JS:
function UpdateStatus(Status)
{
var Status = $(this).val();
$(function()
{
$.ajax({
url: 'Ajax/StatusUpdate.php?Status='.Status, data: "", dataType: 'json'
});
});
}
My Questions:
1) How do I send the contents of the text area into the onclick function?
2) How do I escape/urlencode etc.. So it retains line breaks
<textarea name='Status'> </textarea>
<input type='button' value='Status Update'>
You have few problems with your code like using .
for concatenation
Try this -
$(function () {
$('input').on('click', function () {
var Status = $(this).val();
$.ajax({
url: 'Ajax/StatusUpdate.php',
data: {
text: $("textarea[name=Status]").val(),
Status: Status
},
dataType : 'json'
});
});
});