Reputation: 9823
I make an ajax call with:
$.ajax({
type:'post',
url:'abc.php',
success:function(returned_data)
{
// returned_data contains HTML + javascript code
// I'd like to access the javascript variable here
// refer to abc.php's code to see what variable
// somehow access "new_variable" here
}
})
<table id="first_table">
<tr>
.
.
.
<!-- some un-related td content -->
</tr>
</table>
<script>
new_variable = $('#first_table').dataTable();
// now I want new_variable to be available in index.php page; i.e. inside the success
// function of the ajax method
</script>
Can this be achieved? Or any alternative to achieve this?
Upvotes: 0
Views: 46
Reputation: 9823
Surprisingly, the problem seemed to vanish by itself. I don't know what minor change I did or didn't, but simply using:
$.ajax({
type:'post',
url:'abc.php',
success:function(returned_data)
{
console.log(new_variable);
}
})
printed the result appropriately...which didn't happen earlier before asking this question. What's more is since it is global variable, I could access it outside this ajax function too xD
Upvotes: 0
Reputation: 1438
You could do something like this instead:
$.ajax({
type:'post',
url:'abc.php',
success:function(data)
{
var new_variable = $(data).find('#first_table').dataTable();
}
});
Upvotes: 1