Quantcast
Channel: PHP – StuffThatSpins.com
Viewing all articles
Browse latest Browse all 31

JQUERY issues with Google Chrome .ajax() doesn’t load

$
0
0

For the life of me I couldn’t figure out why my JQuery .ajax() call wouldn’t load in Google Chrome. Especially when it worked in Firefox, IE and Safari which I thought is based on the same WebKit browser. Anyhow, I found the issue to be in the data format AND having null vars.

$.ajax({
	type: "GET",
	data: "action=load=<? echo $php_load ?>&channel_id="+channel_id+"&color="+channel_color+"&login_id=" + <? echo $login_id; ?>,
	url: "index_feed_ajax.php",
	success: function(html)
	{
		alert("here");

		//hide the progress bar
		$("#loading").fadeOut();	

		//add the content retrieved from ajax and put it in the #content div
		$("#content").html(html);

		//display the body with fadeIn transition
		$("#content").fadeIn('fast');
	}
});

the first problem was the “data” formatting – the following example is incorrect.

	data: "action=load=<? echo $some_var ?>&channel_id="+channelId+"&color="+channelColor+"&login_id=" + <? echo $login_id; ?>,

data: should be in this format:

$.ajax({url: "index_feed_ajax.php",
      data: {
            load_feed: loadVar,
            channel_id: channelId,
            color: channelColor,
            login_id: loginId
        },
        method: 'GET',
		success: function(html){
			//alert("here");

			//hide the progress bar
			$("#loading").fadeOut();	

			//add the content retrieved from ajax and put it in the #content div
			$("#content").html(html);

			//display the body with fadeIn transition
			$("#content").fadeIn('fast');
		},                    

        error: function(HttpRequest, textStatus, errorThrown) {
        alert(textStatus+" - "+errorThrown);
        }
    });

You’ll also noticed that I changed the PHP vars. I ALSO found out if the php vars were null they would create errors in the javascript console.
I set some javascript vars with PHP values before these functions run.

<script type='text/javascript'>
	loginId = "<? echo $session->login_id; ?>";
	if ( loginId == null || loginId == "") loginId = 0;
	//alert ("header loginId: " + loginId );

	load_var = "<? $_SESSION['load']; ?>";
	if ( sessionLoad == null || sessionLoad == "") {
		loadVar = "some_value";
	}
	//alert ("loadVar: " + loadVar );

Viewing all articles
Browse latest Browse all 31

Trending Articles