Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  87] [ 4]  / answers: 1 / hits: 61142  / 12 Years ago, thu, february 28, 2013, 12:00:00

I want to alert the return value from a php method, but nothing happens. Here is the ajax and php methods. Can anyone see what I am doing wrong?



--------------------------------------…
Ajax script



$.ajax({
type: 'get',
url: '/donation/junk/4',
data: datastring,
success: function(data) {
alert(data');
}
});


--------------------------------------…
php method



function junk($id)
{
return works11;
}

More From » php

 Answers
32

in PHP, you can't simply return your value and have it show up in the ajax response. you need to print or echo your final values. (there are other ways too, but that's getting off topic).



also, you have a trailing apostrophe in your alert() call that will cause an error and should be removed.



Fixed:



$.ajax({
type: 'get',
url: '/donation/junk/4',
data: datastring,
success: function(data) {
alert(data);
}
});


PHP:



function junk($id)
{
print works11;
}

[#79947] Wednesday, February 27, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;