JavaScript
x
18
18
1
$.ajax({
2
type: 'POST',
3
headers: { "cache-control": "no-cache" },
4
url: baseDir + 'somepage.php?ajax=true&rand=' + new Date().getTime(),
5
async: true,
6
cache: false,
7
dataType : "script",
8
data: 'somedata=' + JSON.stringify(something),
9
success: function(jsonData)
10
{
11
//do something
12
},
13
error: function(XMLHttpRequest, textStatus, errorThrown)
14
{
15
//error
16
}
17
});
18
I have this code which works ok, the response from page somepage.php is this:
JavaScript
1
3
1
somefunction(55, new Array('1', '2', '3'), 0, 0, 0);
2
$('#someid').val('123');
3
Which is evaluated as JavaScript and returns it as plain text.
My question is: how do I put the output into a debug <textarea id="something"><textarea>
… or a div, to view the output for debugging?
Advertisement
Answer
Use jQuery.text();
JavaScript
1
5
1
error: function(XMLHttpRequest, textStatus, errorThrown)
2
{
3
$('#myDiv').text(textStatus)
4
}
5
Cheers!