Ajax不发布数据,Chrome扩展程序 [英] Ajax Not Posting Data, Chrome Extension

查看:119
本文介绍了Ajax不发布数据,Chrome扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Chrome扩展程序中,我能够访问我的'punch.php'文件并接收数据,问题是我似乎无法将数据传递到该文件。这是我的代码:

In my Chrome Extension I'm able to get to my 'punch.php' file and receive data back, the problem is that I don't seem to be able to pass data to the file. Here's my code:

jQuery.fn.punch = function(){
    $(this).click(function(){
        var punchBtn = $(this);
        var ProjectMemberId = '1'
        var ProjectId = '1'
        var str = 'ProjectMemberId='+ProjectMemberId+'&ProjectId='+ProjectId;

        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://www.ontimepunchcard.com/scripts/punch.php", true);
        xhr.onreadystatechange = function() {
          if (xhr.readyState == 4) {
              $('#PunchBox').html(xhr.responseText);
              if(xhr.responseText==0)
              {
                  punchBtn.removeClass('PunchedIn');
              }
              else
              {
                  punchBtn.addClass('PunchedIn');
              }
          }
        }
    xhr.send('ProjectMemberId='+ProjectMemberId+'&ProjectId='+ProjectId);
    });
}//END PUNCH METHOD

这是所有普通Web应用程序的重复相同的代码。 Id的帖子为'punch.php',并且是SQL语句的一部分。该声明失败了Chrome扩展,并返回一个错误语句,所以我开始回应实际的SQL查询,看看它试图做什么。结果是带有两个Id的SQL查询丢失,因此错误和查询失败。

This is a duplication of a normal web application with all of the same code. The Id's post to 'punch.php' and are a part of an SQL statement. The statement was failing with the Chrome extension, and returning an error statement, so I began echoing out the actual SQL query to see what it was trying to do. The result was the SQL query with the two Id's missing, hence the error and failed query.

这里有句法问题吗?有没有可能,尽管我有权限设置谷歌说我应该的方式,我的扩展只能接收数据而不发送?

Do I have a syntax problem here? Is it possible that though I have the permissions set the way Google says I should, that my extension can only receive data and not send? Is there some other foolishness going on here?

推荐答案

您确定您的扩展程序中有适当的权限来发布数据文件?我只做了一个简单的片段,我从responseText返回1。就我所见,片段是好的,只要它在扩展页面(而不是内容脚本)中运行 - Mohamed Mansour 1月9日在23:45

"Are you sure you have proper permissions in your extensions to post data to that file? I just did a simple snippet that I return "1" from responseText. As far as I can see, the snippet is good, as long as it runs in the extension page (not the content script) – Mohamed Mansour Jan 9 at 23:45"

显然这是答案。

这篇关于Ajax不发布数据,Chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆