Reputation: 867
I am working in extjs.I want to find weather of specific city. i got reference from"http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/pune.json". Its giving all information related to given city in json format, by writing following code in html file-
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
</script>
<script>
jQuery(document).ready(function($) {
$.ajax({
url : "http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/Pune.json",
dataType : "jsonp",
success : function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_c = parsed_json['current_observation']['temperature_string'];
alert("Current temperature in "
+ location + " is: " + temp_c);
}
});
});
</script>
Its working correctly. Now i want to integrate this jquery code in extjs's controller. So can someone guide me how to integrate above jquery code in extjs?
Upvotes: 0
Views: 796
Reputation: 86
In both sencha touch and extjs all your javascript code is to be placed in your app.js file or other class js files. You would never put code like that in a script tag in the html. If you want to make a call to that location before your app loads or first thing you would put it in your Application launch function or put it directly above.
//DO YOUR AJAX CALL HERE BEFORE YOUR APPLICATION LAUNCHES
Ext.application({
name: 'MyApp',
launch: function() {
//OR INSIDE THE LAUNCH FUNCTION
}
});
Upvotes: 0
Reputation: 3320
There is no conflict between ExtJS and jQuery (both have their own namespace). You can use jQuery in your ExtJS controllers as long as jQuery is loaded before your app.js. I use jQuery with ExtJS since ExtJS 4.x and never had any issue.
Upvotes: 0
Reputation: 181
Following extjs code does the same that yours, so you can use it inside of the controller.
Ext.data.JsonP.request({
url:"http://api.wunderground.com/api/4ab310c7d75542f3/geolookup/conditions/q/IA/Pune.json",
success : function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_c = parsed_json['current_observation']['temperature_string'];
alert("Current temperature in " + location + " is: " + temp_c);
}
});
Upvotes: 2