【问题标题】:send image from jquery-mobile funtion ajax to web service将图像从 jquery-mobile 功能 ajax 发送到 Web 服务
【发布时间】:2015-02-12 20:18:46
【问题描述】:

我需要从 jquery mobile 制作的页面发送照片。

这是html代码:

 <div data-role="content" >


                 <a  data-role="button" data-theme="c" href="tel:902765555">llama Alvarez Abogados</a>
                 <br>  
                  <div id="avisoResultadosContacto" ></div>

                 <div >
                    <b>O mandanos tus datos para que nos pongamos en contacto contigo</b>
                 <br>
                </div>
                 <div data-role="fieldcontain">

                        <b>Hazle una foto a la multa</b>                        
                        <button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-camera">Foto multa</button>
                        <img id="foto" src="./foto.jpg"/>
                        <b>Al menos necesitamos un correo</b>
                        <input type="email" name="email" id="email" value="" placeholder="Email *" />
                        <b>Si tu quieres, ser&aacute; m&aacute;s r&aacute;pido contactar</b>
                        <input  name="telf" id="telf" value="" placeholder="Tel&eacute;fono"  />
                        <b>Por favor incluye la fecha en la que te llego la multa</b>
                        <input type="text" id="calendario" data-role="date" data-inline="true">
                        <br>
                        <textarea cols="20" rows="40" maxlength="300" style="max-height:10px;" name="textarea-1" id="textarea-1" class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset" placeholder="Observaciones"></textarea>
                        <br>
                        <a data-role="button"  id="enviarDatos"   onclick="enviarDatos()" value="Enviar datos" data-theme="b">Enviar datos</a>

                 </div>
            </div>

而jquery函数是:

var sUrlBusqueda = "http://"+hostwebservice+"/rest/mail";

                var email       = $("#email").val();
                var telf        = $("#telf").val();
                var textarea    = $("#textarea-1").val();


                var parametros = {
                    "email"     : email,
                    "telf"      : telf,
                    "textarea"  : textarea,

那个参数加在这里????????? };

                 $.ajax({
                      data: parametros, 
                      type: "post",  
                      url: sUrlBusqueda,
                      async: true,
                      success: function (response) {
                                $("#avisoResultadosContacto").html("ok");

                       //  alert("enviado");                  
                      },
                      error: function (response) {

                          $("#avisoResultadosContacto").html("nook");

                       // alert("error");
                      }
                    });

我可以在图像中发送参数吗?我需要将文件从图像发送到网络服务,它是如何发送的和数据?

【问题讨论】:

    标签: jquery web-services cordova jquery-mobile


    【解决方案1】:

    您必须将这两个参数添加为false:

    contentType: false
    processData: false
    

    假设您在表单上有所有参数和图像(来自输入文件),它应该是这样的:

               var data = new FormData($('#form')[0]);
               $.ajax({
                    url: sUrlBusqueda,
                    data: data,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    error: function (response) {
    
                        $("#avisoResultadosContacto").html("nook");
    
                           // alert("error");
                    },
                    success: function (response) {
                        $("#avisoResultadosContacto").html("ok");
    
                        //  alert("enviado");                  
                    }
                });
    
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    相关资源
    最近更新 更多