Reputation:
So when I run my set of code independant of the Chrome extension frame work aka in a dummy html file it works fine but when I try to do it out of the chrome extension wikipedia gives me this weird callback function tacked onto my API url.
http://en.wikipedia.org/w/api.php?action=query&titles=Girdling&format=json&prop=extracts&exintro=0&redirects&callback=jQuery1111023737464868463576_1402806465025
What I am actually running in my AJAX call.
var wikiUrl = "http://en.wikipedia.org/w/api.php?action=query&titles=Girdling&format=json&prop=extracts&exintro=0&redirects&callback=?"
$.ajax(wikiUrl,{
dataType: 'jsonp',
cache: true,
success: function(data){
//do things with the response data
}
I get this Error in the console:
Uncaught ReferenceError: jQuery1111023737464868463576_1402806465025 is not defined
As you might suspect the JSON data is wrapped in this function:
jQuery1111023737464868463576_1402806465025({"query":{"pages":{"1822951":{"pageid":1822951,"ns":0,"title":"Girdling","extract":"<p><b>Girdling</b>, also called <b>ring barking</b> or <b>ring-barking</b>, is the complete removal of a strip of bark (consisting of cork cambium, phloem, cambium and sometimes going into the xylem) from around the entire circumference of either a branch or trunk of a woody plant. Girdling results in the death of the entire tree over time. A branch completely girdled will fail and when the main trunk of a tree is girdled, the entire tree will die, if it cannot regrow from above to bridge the wound.</p>\n<p>Among the causes of girdling are human practices, including forestry, horticulture, and vandalism. Foresters use the practice of girdling to thin forests and orchardists use it as a cultural technique to yield larger fruit. Girdling can also be caused by herbivorous mammals feeding on plant bark and by birds and insects, both of which can effectively girdle a tree by boring rows of adjacent holes.</p>\n<p></p>"}}}})
So how do I tell Wikipedia API that I want it to run the success function when it works not that other function? I already tried setting callback=success in my url.
Upvotes: 1
Views: 727
Reputation:
Fixed it somehow? I think some protocol included in most modern sites, but not in my dummy.html site, is that you have to include the type of request it is? (even though it should default to GET?)
AJAX:
var wikiUrl = "http://en.wikipedia.org/w/api.php?action=query&titles="+wikiTitle+"&format=json&prop=extracts&exintro=0&redirects"
$.ajax(wikiUrl,{
type:"GET",
cache: true,
success: function(data){
//do stuff
I also removed the callback=?
from the end of my URL. That might have the combination of those two did it for me.
Upvotes: 1