2012-04-20 86 views
0

溝通我正在構建一個移動應用程序(html5/javascript + PhoneGap)與GAE作爲後端服務器(Java)。經過幾天的研究仍然無法獲得全貌。移動應用程序(html5/javascript)與谷歌應用程序引擎示例

在通信部分是否有這種配置的開源示例?主要是OAuth,從手機客戶端發送/接收數據,用戶通道API,推送通知等。

GAE中的所有示例都是針對網絡應用程序,但不適用於我認爲的外部移動客戶端。這就是爲什麼它完全不同。

我學到了什麼地方XMLHttpRequest不支持跨域通信,所以我不應該使用它?

jQuery.ajax()似乎可以滿足我的要求嗎?再次,一個開源示例項目可以幫助我很多!

任何鏈接/建議,將不勝感激!

謝謝。

+0

如果你的手機客戶端是HTML5和JavaScript,它_is_ web應用程序。你認爲在現有的例子中缺乏什麼? – 2012-04-20 05:38:33

+0

示例假定webapp與GAE處於相同的域。對於不是這種情況的移動應用程序。 – 2012-04-20 09:31:06

+0

您可以在應用引擎上設置一個平穩的框架,例如球衣。 – aglassman 2012-04-20 17:00:39

回答

0

在通信部分是否有這種配置的開源示例?

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

謝謝!但你怎麼能夠插入?我無法做到這一點。 – user1405141 2014-02-17 22:12:45

+0

你的編輯是有道理的,我想我知道將來如何去做;但是有什麼我需要做「接受」你的編輯? – user1405141 2014-02-18 04:15:42