无法弄清楚如何对谷歌应用引擎进行XMLHttpRequest

Lio*_*kel 4 javascript ajax google-app-engine google-chrome google-chrome-extension

我正在尝试从javascript(谷歌浏览器扩展程序)到我的谷歌应用程序进行简单的POST我可以看到HTTP POST确实被发送到GAE服务器,但我无法想象如何传输简单的文本字符串,并在谷歌应用程序中使用它.

目标:使用xmlhttpRequest从javascript发送字符串,在google-app网页上显示此字符串.

这是javascript的代码:

  function onRequest(request, sender, sendResponse) {
    var url = request;
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "http://myapp.appspot.com");
    xhr.send(url);
    // Return nothing to let the connection be cleaned up.
    sendResponse({});
  };
Run Code Online (Sandbox Code Playgroud)

这是我如何处理服务器端的帖子:

def post(self):
    url1 = str(self.request.get('url1'))
    self.response.headers['Content-Type'] = 'text/html'
    self.response.out.write('<p>URL is: %s</p>' % url1)
Run Code Online (Sandbox Code Playgroud)

当我看到POST响应时,我看到了

<p>URL is: </p>
Run Code Online (Sandbox Code Playgroud)

发送的var url在哪里?

Lio*_*kel 5

我以不同的方式让它工作.我使用jquery代替XMLHttpRequest:

    $.post("http://myapp.appspot.com", { url1: request});
Run Code Online (Sandbox Code Playgroud)

它工作:)

顺便说一下,我还发现如果你想让chrome扩展的html使用jquery,你需要这样做

<script src="jquery-1.5.1.js"></script>
<script> your code here </script>
Run Code Online (Sandbox Code Playgroud)

(我相信这对你们来说很基本但对我来说很新鲜:)