2

我创建了简单的 html 表单,其中包含文本输入、文本区域、上传图像等文件。

在将其转换为包含用户注册到他的数据和照片和简历文档的电话间隙应用程序时,我如何提交此表单数据?

提交数据时,它应该被发送到 mysql 插入将举行的 php 页面?

我已经尝试过序列化方法在获取 php 页面中的数据时遇到问题

也找不到上传文件和图片的方法??

有什么帮助吗???

4

2 回答 2

2
  <script>

document.addEventListener("deviceready", onDeviceReady, false);

 function onDeviceReady() {

console.log("你好"); $("#button").click(function(evt){ var name = $("#name").val(); var message = $("#message").val(); var sendData = { "名称”:名称,“消息”:消息};

$.ajax({
    type: "POST",
    url: "http://localhost/webs/main/ajax/process.php",
    data: sendData,
    success: function(data) {
        log.console(data);
         $("#info").html(data);

    }

});

 alert("Hello ");
 alert($("#test").val());
 alert($("#name").val());
 alert($("#message").val());
 return false;

}); }

于 2013-10-24T09:04:06.033 回答
1
Upload image using phonegap
============================

function uploadImage(){
       //Using Camera
       navigator.camera.getPicture(uploadPhoto, onFailcapturePhoto, { quality: 50,destinationType: Camera.DestinationType.FILE_URI }); 
        //Using library            
       navigator.camera.getPicture(uploadPhoto, onFailcapturePhoto, { quality: 50,destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY});    
}

function onFailcapturePhoto(message) {    
   console.log("Message = " + message);
}

function uploadPhoto(imageURI) {
  var imagefile = imageURI; 
  $('#vImage').attr('src', imagefile);
/* Image Upload Start */
var ft = new FileTransfer();                     
var options = new FileUploadOptions();                      
options.fileKey="vImage1";                      
options.fileName=imagefile.substr(imagefile.lastIndexOf('/')+1);
options.mimeType="image/jpeg";  
var params = new Object();
params.value1 = "test";
params.value2 = "param";                       
options.params = params;
options.chunkedMode = false;                       
ft.upload(imagefile, your_service_url, win, fail, options);   
}

function win(r) {
  console.log("Code = " + r.responseCode);
   console.log("Response = " + r.response);
   //alert($.parseJSON(r.response))    
}

function fail(error) {
   console.log("Response = " +  error.code);
} 
On your php file 
=================
 file_put_contents("file.txt", print_r($_FILES, true));
 Post Form data and Image together 
 ================================ 
// Here first submit your form input data after successfully submit upload image call

$('#submit').on('click', function(event){
if(event.handled !== true)
{
    var ajax_call = serviceURL; 
    var str = $('#form').serialize();
    $.ajax({
        type: "POST",
        url: ajax_call,
        data: str,
        dataType: "json",
        success: function(response){              
            $.each(response, function(key, value) {
                // after success submit data
                if(response){
                    var imagefile = $('#vImage').attr('src');
                    /* Image Upload Start */    
                    var ft = new FileTransfer();                     
                    var options = new FileUploadOptions();                      
                    options.fileKey="vImage1";                      
                    options.fileName=imagefile.substr(imagefile.lastIndexOf('/')+1);
                    options.mimeType="image/jpeg";  
                    options.mimeType="image/png"; 
                    var params = new Object();
                    params.value1 = "test";
                    params.value2 = "param";                       
                    options.params = params;
                    options.chunkedMode = false;                       
                    ft.upload(imagefile, your_service_url, win, fail, options);

                  }                                     
            });
        }
    });
    event.handled = true;
}
return false;
})
于 2013-10-24T07:53:08.197 回答