I am trying to write a sample extension, this is how it should work. My extension has an option page, when people click on the sign-in button, it sends an ajax request to test.php and gets information to alert user. But it does not work, I don't know why. this is my folder structure
chrome
\ manifest.json
\ options.html
\ options.js
\ test.php
in options.html
<div class="login-button" id="login-button">Sign in</div>
in options.js
$(document).ready(function(){
alert('hello');
$('#login-button').click(function() {
loginAjax();
});
})
function loginAjax() {
$.ajax({
url: 'test.php',
data: "",
dataType: 'json',
success: function(data) {
alert(data);
}
});
}
In the Ajax URL I tried to put an absolute path, but it does not work.
Thanks in advance.
Edit: It already work, i don't know:-D
您必须使用跨域XMLHttpRequest而不是jquery查看更多http://code.google.com/chrome/extensions/xhr.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.