移动应用(html5/javascript)与Google App Engine示例通信

Mobile app (html5/javascript) communicate with Google App Engine example

本文关键字:App Google Engine 通信 应用 html5 javascript 移动      更新时间:2023-09-26

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

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

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

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

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

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

谢谢。

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

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));
                }
  });