Skip to content

Instantly share code, notes, and snippets.

@karanjamutahi
Created April 5, 2017 17:46
Show Gist options
  • Save karanjamutahi/eb8c7afb71440d642bd05bf20dee1193 to your computer and use it in GitHub Desktop.
Save karanjamutahi/eb8c7afb71440d642bd05bf20dee1193 to your computer and use it in GitHub Desktop.
var apiURL = "";
var title = "";
$(document).ready(function(){
$.support.cors = true; //doesn't seem to do anything
$.ajaxSetup({
headers: {'Access-Control-Allow-Origin':'*',
'Content-Type':'text/plain' //trying to make it a simple request because it was sending an OPTIONS request
}
});
console.log("Twende Kazi");
$("#searchbtn").on("click",function(){
console.log("clicked");
var query = $("#query").val();
console.log(query);
$("#query").val(""); //Reset TextField
apiURL = "http://en.wikipedia.org/w/api.php?action=query&list=allpages&apprefix="+query+"&aplimit=15&format=json";
console.log(apiURL);
/* $.ajax({
cache:false,
url:apiURL,
method:"GET",
})
//we need to add cross-origin-sharing headers.
.done(function(result){
title = result.query.allpages[0].title;
console.log(title);
});
*/
$.getJSON(apiURL,function(response){
console.log(response);
});
//close the getjson method
});
});
/*
The Error I'm getting.
XMLHttpRequest cannot load http://en.wikipedia.org/w/api.php?action=query&list=allpages&apprefix=zipper&aplimit=15&format=json. Response for preflight is invalid (redirect)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment