According to this answer, it is better to use the $.ajax()
function:
$('.showprayer').click( function(event) {
$.ajax({
url: '/show_prayer',
type: 'POST',
data { 'name' : $(this).text() },
dataType: 'script'
});
});
rather than the $.post()
function:
$('.showprayer').click( function(event) {
$.post('/show_prayer', { 'name' : $(this).text() }, function(data) {
eval(data);
});
});
The reason given is:
The difference is that this uses `jQuery.globalEval()` which sticks the script
in the <head> as if it were a normal GET requested <script>, instead of actually
calling `eval()` on it.
My question is, if this is correct, why is it important for the script to end up in the ? Does that make a big difference over using eval()?