简体   繁体   English

Ajax无法在Chrome扩展程序中使用吗?

[英]Ajax not working in Chrome extension?

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. 我的扩展程序有一个选项页,当人们单击登录按钮时,它会向test.php发送ajax请求并获取信息以提醒用户。 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 在options.html中

<div class="login-button" id="login-button">Sign in</div>

in options.js 在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. 在Ajax URL中,我尝试放置绝对路径,但是它不起作用。

Thanks in advance. 提前致谢。

Edit: It already work, i don't know:-D 编辑:它已经工作,我不知道:-D

您必须使用跨域XMLHttpRequest而不是jquery查看更多http://code.google.com/chrome/extensions/xhr.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM