[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

My jquery .load returns HTML in Chrome, but all other browsers it returns "0"

Posted on 2013-01-14
6
Medium Priority
?
271 Views
Last Modified: 2013-01-20
This is the javascript (relevant line) - I'm using wordpress, hence the call to the admin page with an action parameter...
$j('#city_statistics-div').load('wp-admin/admin-ajax.php', { action: 'city_statistics', t: '-1' });

Open in new window


this is the php
/*
 * City & Timezone Form
 */
function ttw_city_statistics() {
	$city_id = $_REQUEST[POST_CITY_URL];
	if( $city_id ) {
		echo ttw_city_statistics_html( $city_id );
	}
	die();
}


function ttw_city_statistics_html( $city ) {
	if( -1 == $city) {
		$select  = 'Latitude <input type="text" size="15" name="latitude" id="latitude" value="" />';
		$select .= 'Longitude <input type="text" size="15" name="longitude" id="longitude" value="" />';
		$select .= 'TimeZone ' . ttw_timezone_dropdown_html( '+00:00' );
		$select .= '<input type="checkbox" name="daylight" id="daylight" />Observes Daylight Savings';
	} elseif( 0 < $city ) {
		$result = ttw_get_city_sp( $city ) ;
		$select  = 'Latitude <input type="text" size="15" name="latitude" id="latitude" value="' . $result->Latitude . '" />';
		$select .= 'Longitude <input type="text" size="15" name="longitude" id="longitude" value="' . $result->Longitude . '" />';
		$select .= 'TimeZone ' . ttw_timezone_dropdown_html( $result->TimeZone );
		$select .= '<input type="checkbox" name="daylight" id="daylight" ' . (($result->daylight) ? 'checked=checked' : '') . ' />Observes Daylight Savings';
	}
		
	return $select;
}

Open in new window


In Chrome it works great - I get the input boxes I'm looking for.  In all other browsers, instead of the html, a "0" is printed in the div....

What silly thing have I forgotten????!
0
Comment
Question by:PaultheBroker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 38778025
Not sure how your code works in any browser. You're loading a php file which contains 2 functions and there is no explicit call to either of them. If you just call that script normally, you will get no output, because the actual functions are never called.
0
 
LVL 6

Author Comment

by:PaultheBroker
ID: 38778482
Sure.  The function is being called.  As  i said ... its Wordpress.  I omitted this as being irrelevant -

add_action( 'wp_ajax_city_statistics' , 'ttw_city_statistics' );

Not to give you a Wordpress tutorial, but the call to the admin-ajax.php page with the action=city_statistics triggers the wordpress 'action' "wp_ajax_city_statistics" which then causes ttw_city_statistics() to be called.  That's just the way WordPress likes to roll - it ensures the WordPress framework is loaded when you perform the ajax call.
0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 38778753
Ah. OK, that makes sense. Not sure I can really help on this one - sorry!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Author Comment

by:PaultheBroker
ID: 38779647
Update - I thought that the ajax call was working but now that I test it on another computer, it seems nothing is working...so this might be a general ajax thing.
0
 
LVL 6

Accepted Solution

by:
PaultheBroker earned 0 total points
ID: 38781605
OK - thanks for your help.  I'm officially a dolt....the ajax call I was making required me to be logged in to work...which is why it worked in Chrome (because I had logged in there) but not anywhere else.  

add_action( 'wp_ajax_nopriv_city_statistics' , 'ttw_city_statistics' );

is the way to call ajax from WordPress if you aren't logged in :S
0
 
LVL 6

Author Closing Comment

by:PaultheBroker
ID: 38798132
I figured this out finally....after a lot of wasted time!  I hope it helps someone else - or I might just delete it out of shame!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question