【问题标题】:Mobile app (html5/javascript) communicate with Google App Engine example移动应用 (html5/javascript) 与 Google App Engine 通信示例
【发布时间】:2012-04-20 01:07:13
【问题描述】:

我正在构建一个使用 GAE 作为后端服务器 (Java) 的移动应用程序 (html5/javascript + PhoneGap)。经过几天的研究仍然无法获得全貌。

在通信部分是否有此类配置的开源示例?主要是OAuth,从移动客户端发送/接收数据,用户Channel API,推送通知等。

GAE 中的所有示例都适用于 Web 应用程序,但我认为不适用于外部移动客户端。这就是为什么它完全不同。

我在某处了解到 XMLHttpRequest 不支持跨域通信,所以我不应该使用它吗?

jQuery.ajax() 似乎可以满足我的要求?同样,一个开源示例项目可以帮助我很多!

任何链接/建议将不胜感激!

谢谢。

【问题讨论】:

  • 如果您的移动客户端是html5和javascript,它一个webapp。您认为现有示例中存在哪些不足?
  • 示例假设 webapp 与 GAE 位于同一域中。对于移动应用,情况并非如此。
  • 您可以在应用引擎上设置一个restful框架,例如jersey。
  • jQuery.ajax() == XMLHttpRequest。我是回答你另一个问题的人。您应该使用本地应用引擎开发服务器进行测试,您不应该每次更改代码时都进行部署。
  • 为什么移动应用的域会有所不同?唯一的区别是您使用的是移动浏览器而不是桌面浏览器。

标签: javascript html google-app-engine


【解决方案1】:

在通信部分有这种配置的开源示例吗?

https://github.com/blueimp/jQuery-File-Upload

或者,进一步调查 jquery ajax 调用...

function uploadPicture() {

  // blog.w3villa.com/websites/uploading-filesimage-with-ajax-jquery-without-submitting-a-form/
  // 

  var form_data = new FormData();      // Creating object of FormData class
  var file_data = photo.src;   // Getting the properties of file from file field
  // form_data.append("file", file_data);  // Appending parameter named file with properties of file_field to form_data
  // var blob = new Blob([file_data], {type: 'image/png'});
  // form_data.append("file", blob)

  var dataURI = photo.src;

  alert(dataURI);

  form_data.append("file", dataURItoBlob(dataURI));

  form_data.append("field1", "stuff1");     // Adding extra parameters to form_data
  alert(JSON.stringify(form_data));

  $.ajax({
      url: serverURL,
      dataType: 'json',    // the format of the response
      cache: false,
      contentType: false,  // the format of data being sent to the server as part of request
      //                      shazwazza.com/post/Uploading-files-and-JSON-data-in-the-same-request-with-Angular-JS
      //                      setting the Content-type to 'false' will force the request to automatically
      //                      populate the headers properly including the boundary parameter.
      // stackoverflow.com/questions/2845459/jquery-how-to-make-post-use-contenttype-application-json
      // contentType:"application/json; charset=utf-8",
      // contentType:"multipart/form-data; charset=utf-8",
      processData: false,    // do not convert outgoing data to a string
      data: form_data,       // Setting the data attribute of ajax with file_data
      type: 'post',
      success: function(data) {
                alert("success! data: " + JSON.stringify(data));
                }
  });

【讨论】:

  • 谢谢!但是您是如何插入 的呢?我无法做到这一点。
  • 您的编辑很有道理,我想我知道将来该怎么做;但是我需要做些什么来“接受”您的编辑吗?
猜你喜欢
  • 1970-01-01
  • 2019-01-17
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 2016-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多