I’m trying to write a Google Chrome extension to put autocomplete in certain fields on the internal wiki. It does a JQuery script inject. Anyway, the autocorrect fields are on a webpage, behind a login. After one logs in, the browser prompts you to download an HTML file, and the file is in json format. That’s the data I need to load into the autocomplete. So far my script looks like this…
$(document).ready(function(){
alert("Thanks for visiting!");
var data = $.ajax({
url: "URL",
data: data,
success: success,
dataType: dataType
});
function setAutocomplete(){
$("input").autocomplete({
source: [data]
});
};
$("#COST_JOB_NUM").live("click", function(){
setAutocomplete();
});
});
I know there’s no log in credentials there so it can’t be working, but I can’t seem to find a solution anywhere. I know the autocomplete plugin itself works, so it’s an issue of getting the data. Any help?
Content scripts are not allowed to make cross-domain ajax requests (just like regular scripts on a page).
You would need to move your ajax request to a background page that doesn’t have such limitation (as long as you declared corresponding host permissions in the manifest).
You can communicate between content script and background page through messaging.