I was just wondering if this was proper.
Is it possible to execute javascript code that has been return from an Ajax call?
ser = $('#new_customer_ input').serialize();
$.ajax({
type: 'POST',
url: "ajax/newCustomer.php",
data: ser,
success: function(data)
{
$('div#result').html(data);
}
});
Suppose the php file returns something like this:
<script>$('input#customer_name').val('something');</script>
which would be executed upon response.
This works, although my question is: is this correct or should I be doing something else?
You can use
for that. But make sure about the code in the string is from a very reliable source, (may be from your on web service).
The way you are doing it is correct. And better not use eval