HighDots Forums  

jQuery $.get callback function not being called

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss jQuery $.get callback function not being called in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ArnieML
 
Posts: n/a

Default jQuery $.get callback function not being called - 11-07-2009 , 06:53 PM






Hello, I hope someone can help. I'm issuing the following ajax jquery
call:

$.get("/ajaxtest.php", { ajax: "true", east: northEast.lng(), west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(), mood:
amood },
function (data) {
for(var i=0; i<data.length; i++){
alert("now processing tweets");
display_tmmmarker(map, data[i], i);
}
$("#gettingtweets").remove();

}, 'json');


The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
$east = $_REQUEST['east'];
$south = $_REQUEST['south'];
$west = $_REQUEST['west'];
$north = $_REQUEST['north'];
$mood = $_REQUEST['mood'];

$tweets = get_tmmtweets($east, $south, $west, $north, $mood);

json_encode($tweets);
}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put in
an alert statement in the callback to verify if the function has been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
  #2  
Old   
Michel Belleville
 
Posts: n/a

Default Re: [jQuery] jQuery $.get callback function not being called - 11-08-2009 , 02:20 AM






It's been a long time since my last PHP days but shouldn't you echo or print
something to get it sent ? It seems you'd get an empty response here (unless
json_encode already outputs the answer to the response). And as you expect
at least a bit of json to run through and output parts of, your callback may
be called but not do anything about the empty response.

Hope it helps.

Michel Belleville


2009/11/8 ArnieML <arnie.lapinig (AT) gmail (DOT) com>

Quote:
Hello, I hope someone can help. I'm issuing the following ajax jquery
call:

$.get("/ajaxtest.php", { ajax: "true", east: northEast.lng(), west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(), mood:
amood },
function (data) {
for(var i=0; i<data.length; i++){
alert("now processing tweets");
display_tmmmarker(map, data[i], i);
}
$("#gettingtweets").remove();

}, 'json');


The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
$east = $_REQUEST['east'];
$south = $_REQUEST['south'];
$west = $_REQUEST['west'];
$north = $_REQUEST['north'];
$mood = $_REQUEST['mood'];

$tweets = get_tmmtweets($east, $south, $west, $north, $mood);

json_encode($tweets);
}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put in
an alert statement in the callback to verify if the function has been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
  #3  
Old   
ArnieML
 
Posts: n/a

Default Re: jQuery $.get callback function not being called - 11-08-2009 , 12:16 PM



Hi Michel,

I added the following statement after json encoding:

echo $tweets;

to the PHP, but the callback function still isn't getting called.

Any other ideas?

Thanks for the help.

On Nov 7, 11:20*pm, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com>
wrote:
Quote:
It's been a long time since my last PHP days but shouldn't you echo or print
something to get it sent ? It seems you'd get an empty response here (unless
json_encode already outputs the answer to the response). And as you expect
at least a bit of json to run through and output parts of, your callback may
be called but not do anything about the empty response.

Hope it helps.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hello, I hope someone can help. I'm issuing the following ajax jquery
call:

* * * *$.get("/ajaxtest.php", { ajax: "true", east: northEast.lng(), west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(), mood:
amood },
* * * *function (data) {
* * * * * * * *for(var i=0; i<data.length; i++){
* * * * * * * *alert("now processing tweets");
* * * * * * * *display_tmmmarker(map, data[i], i);
* * * * * * * *}
* * * * * * * *$("#gettingtweets").remove();

* * * *}, 'json');

The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
* * * *$east * = $_REQUEST['east'];
* * * *$south *= $_REQUEST['south'];
* * * *$west * = $_REQUEST['west'];
* * * *$north *= $_REQUEST['north'];
* * * *$mood * = $_REQUEST['mood'];

* * * *$tweets = get_tmmtweets($east, $south, $west, $north, $mood);

* * * *json_encode($tweets);
* * * *}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put in
an alert statement in the callback to verify if the function has been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
  #4  
Old   
Michel Belleville
 
Posts: n/a

Default Re: [jQuery] Re: jQuery $.get callback function not being called - 11-08-2009 , 02:14 PM



Well the doc suggests
<http://php.net/manual/fr/function.json-encode.php>that json_encode
doesn't change the variable passed as a parameter but
returns the encoded string so you've got to do something like this :
echo json_encode($tweets);

To get a jason encoded serialisation of your data output in the response and
not :
json_encode($tweets);
echo $tweets;

Which would only output $tweets not encoded.

Though if it doesn't work like I tell you, you'd better worry about
something else and I don't know exactly what at this point.

Michel Belleville


2009/11/8 ArnieML <arnie.lapinig (AT) gmail (DOT) com>

Quote:
Hi Michel,

I added the following statement after json encoding:

echo $tweets;

to the PHP, but the callback function still isn't getting called.

Any other ideas?

Thanks for the help.

On Nov 7, 11:20 pm, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com
wrote:
It's been a long time since my last PHP days but shouldn't you echo or
print
something to get it sent ? It seems you'd get an empty response here
(unless
json_encode already outputs the answer to the response). And as you
expect
at least a bit of json to run through and output parts of, your callback
may
be called but not do anything about the empty response.

Hope it helps.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hello, I hope someone can help. I'm issuing the following ajax jquery
call:

$.get("/ajaxtest.php", { ajax: "true", east: northEast.lng(),
west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(), mood:
amood },
function (data) {
for(var i=0; i<data.length; i++){
alert("now processing tweets");
display_tmmmarker(map, data[i], i);
}
$("#gettingtweets").remove();

}, 'json');

The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
$east = $_REQUEST['east'];
$south = $_REQUEST['south'];
$west = $_REQUEST['west'];
$north = $_REQUEST['north'];
$mood = $_REQUEST['mood'];

$tweets = get_tmmtweets($east, $south, $west, $north, $mood);

json_encode($tweets);
}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put in
an alert statement in the callback to verify if the function has been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
  #5  
Old   
ArnieML
 
Posts: n/a

Default Re: jQuery $.get callback function not being called - 11-08-2009 , 08:16 PM



I tried echo json_encode($tweets);
and still no callback function. The XMLhttp response header looks like
this:

Date Mon, 09 Nov 2009 00:57:25 GMT
Content-Type text/html
Connection close
Server Apache
X-Powered-By PHP/5.2.1
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Pragma no-cache
Content-Length 20283

Is the Cache-Control setting of no-store, no-cache a possible problem?

Regards,

Arnie

On Nov 8, 11:14*am, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com>
wrote:
Quote:
Well the doc suggests
http://php.net/manual/fr/function.json-encode.php>that json_encode
doesn't change the variable passed as a parameter but
returns the encoded string so you've got to do something like this :
echo json_encode($tweets);

To get a jason encoded serialisation of your data output in the response and
not :
json_encode($tweets);
echo $tweets;

Which would only output $tweets not encoded.

Though if it doesn't work like I tell you, you'd better worry about
something else and I don't know exactly what at this point.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hi Michel,

I added the following statement after json encoding:

echo $tweets;

to the PHP, but the callback function still isn't getting called.

Any other ideas?

Thanks for the help.

On Nov 7, 11:20 pm, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com
wrote:
It's been a long time since my last PHP days but shouldn't you echo or
print
something to get it sent ? It seems you'd get an empty response here
(unless
json_encode already outputs the answer to the response). And as you
expect
at least a bit of json to run through and output parts of, your callback
may
be called but not do anything about the empty response.

Hope it helps.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hello, I hope someone can help. I'm issuing the following ajax jquery
call:

* * * *$.get("/ajaxtest.php", { ajax: "true", east: northEast.lng(),
west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(), mood:
amood },
* * * *function (data) {
* * * * * * * *for(var i=0; i<data.length; i++){
* * * * * * * *alert("now processing tweets");
* * * * * * * *display_tmmmarker(map, data[i], i);
* * * * * * * *}
* * * * * * * *$("#gettingtweets").remove();

* * * *}, 'json');

The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
* * * *$east * = $_REQUEST['east'];
* * * *$south *= $_REQUEST['south'];
* * * *$west * = $_REQUEST['west'];
* * * *$north *= $_REQUEST['north'];
* * * *$mood * = $_REQUEST['mood'];

* * * *$tweets = get_tmmtweets($east, $south, $west, $north, $mood);

* * * *json_encode($tweets);
* * * *}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put in
an alert statement in the callback to verify if the function has been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
  #6  
Old   
Michel Belleville
 
Posts: n/a

Default Re: [jQuery] Re: jQuery $.get callback function not being called - 11-09-2009 , 01:44 AM



Well no, no-store, no-cache, must-revalidate is exactly what you need here.
If you had cache your problem could have been that the cache was keeping a
former result from when you didn't output the result. You should check
wether you get something in the reply, and if not ask yourself why your PHP
script doesn't output anything (my best guess at this point would be that
get_tmmtweets($east, $south, $west, $north, $mood); returns nothing that
json_encode() likes, if anything), though I don't know get_tmmtweets and I
guess I can't help you much here.

Michel Belleville


2009/11/9 ArnieML <arnie.lapinig (AT) gmail (DOT) com>

Quote:
I tried echo json_encode($tweets);
and still no callback function. The XMLhttp response header looks like
this:

Date Mon, 09 Nov 2009 00:57:25 GMT
Content-Type text/html
Connection close
Server Apache
X-Powered-By PHP/5.2.1
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Pragma no-cache
Content-Length 20283

Is the Cache-Control setting of no-store, no-cache a possible problem?

Regards,

Arnie

On Nov 8, 11:14 am, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com
wrote:
Well the doc suggests
http://php.net/manual/fr/function.json-encode.php>that json_encode
doesn't change the variable passed as a parameter but
returns the encoded string so you've got to do something like this :
echo json_encode($tweets);

To get a jason encoded serialisation of your data output in the response
and
not :
json_encode($tweets);
echo $tweets;

Which would only output $tweets not encoded.

Though if it doesn't work like I tell you, you'd better worry about
something else and I don't know exactly what at this point.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hi Michel,

I added the following statement after json encoding:

echo $tweets;

to the PHP, but the callback function still isn't getting called.

Any other ideas?

Thanks for the help.

On Nov 7, 11:20 pm, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com
wrote:
It's been a long time since my last PHP days but shouldn't you echo
or
print
something to get it sent ? It seems you'd get an empty response here
(unless
json_encode already outputs the answer to the response). And as you
expect
at least a bit of json to run through and output parts of, your
callback
may
be called but not do anything about the empty response.

Hope it helps.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hello, I hope someone can help. I'm issuing the following ajax
jquery
call:

$.get("/ajaxtest.php", { ajax: "true", east:
northEast.lng(),
west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(),
mood:
amood },
function (data) {
for(var i=0; i<data.length; i++){
alert("now processing tweets");
display_tmmmarker(map, data[i], i);
}
$("#gettingtweets").remove();

}, 'json');

The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
$east = $_REQUEST['east'];
$south = $_REQUEST['south'];
$west = $_REQUEST['west'];
$north = $_REQUEST['north'];
$mood = $_REQUEST['mood'];

$tweets = get_tmmtweets($east, $south, $west, $north,
$mood);

json_encode($tweets);
}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put
in
an alert statement in the callback to verify if the function has
been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
  #7  
Old   
ArnieML
 
Posts: n/a

Default Re: jQuery $.get callback function not being called - 11-09-2009 , 10:29 PM



Hello Michel,

Thank you very much for your help. I've used Firebug to verify that
json_encode($tweets) outputs json data. But on another php discussion
thread, they suggested to really verify that only json data is being
encoded, without spaces before and after the data. So I'm going to go
through that investigation today. Thanks again!

Regards,

Arnie

On Nov 8, 10:44*pm, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com>
wrote:
Quote:
Well no, no-store, no-cache, must-revalidate is exactly what you need here.
If you had cache your problem could have been that the cache was keeping a
former result from when you didn't output the result. You should check
wether you get something in the reply, and if not ask yourself why your PHP
script doesn't output anything (my best guess at this point would be that
get_tmmtweets($east, $south, $west, $north, $mood); returns nothing that
json_encode() likes, if anything), though I don't know get_tmmtweets and I
guess I can't help you much here.

Michel Belleville

2009/11/9 ArnieML <arnie.lapi... (AT) gmail (DOT) com

I tried echo json_encode($tweets);
and still no callback function. The XMLhttp response header looks like
this:

Date * *Mon, 09 Nov 2009 00:57:25 GMT
Content-Type * *text/html
Connection * * *close
Server *Apache
X-Powered-By * *PHP/5.2.1
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control * no-store, no-cache, must-revalidate, post-check=0, pre-
check=0
Pragma *no-cache
Content-Length *20283

Is the Cache-Control setting of no-store, no-cache a possible problem?

Regards,

Arnie

On Nov 8, 11:14 am, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com
wrote:
Well the doc suggests
http://php.net/manual/fr/function.json-encode.php>that json_encode
doesn't change the variable passed as a parameter but
returns the encoded string so you've got to do something like this :
echo json_encode($tweets);

To get a jason encoded serialisation of your data output in the response
and
not :
json_encode($tweets);
echo $tweets;

Which would only output $tweets not encoded.

Though if it doesn't work like I tell you, you'd better worry about
something else and I don't know exactly what at this point.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hi Michel,

I added the following statement after json encoding:

echo $tweets;

to the PHP, but the callback function still isn't getting called.

Any other ideas?

Thanks for the help.

On Nov 7, 11:20 pm, Michel Belleville <michel.bellevi... (AT) gmail (DOT) com
wrote:
It's been a long time since my last PHP days but shouldn't you echo
or
print
something to get it sent ? It seems you'd get an empty response here
(unless
json_encode already outputs the answer to the response). And as you
expect
at least a bit of json to run through and output parts of, your
callback
may
be called but not do anything about the empty response.

Hope it helps.

Michel Belleville

2009/11/8 ArnieML <arnie.lapi... (AT) gmail (DOT) com

Hello, I hope someone can help. I'm issuing the following ajax
jquery
call:

* * * *$.get("/ajaxtest.php", { ajax: "true", east:
northEast.lng(),
west:
southWest.lng(), north: northEast.lat(), south: southWest.lat(),
mood:
amood },
* * * *function (data) {
* * * * * * * *for(var i=0; i<data.length; i++){
* * * * * * * *alert("now processing tweets");
* * * * * * * *display_tmmmarker(map, data[i], i);
* * * * * * * *}
* * * * * * * *$("#gettingtweets").remove();

* * * *}, 'json');

The PHP page looks like this:

if ( $_REQUEST['ajax'] == 'true' ) {
* * * *$east * = $_REQUEST['east'];
* * * *$south *= $_REQUEST['south'];
* * * *$west * = $_REQUEST['west'];
* * * *$north *= $_REQUEST['north'];
* * * *$mood * = $_REQUEST['mood'];

* * * *$tweets = get_tmmtweets($east, $south, $west, $north,
$mood);

* * * *json_encode($tweets);
* * * *}
exit;

I have verified that the $tweets array has been JSON-encoded using
array_values. But the callback function isn't being invoked. I put
in
an alert statement in the callback to verify if the function has
been
called, but I'm not getting the alert message. Is the $tweets array
not being passed on for some reason?

Can someone help out? Thanks very much!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.