Skip to main content
etiquetas editadas
Enlace
gbianchi
  • 20.6k
  • 13
  • 40
  • 60
se añadieron 1806 caracteres en el cuerpo
Origen Enlace

ok todo lo anterior persiste si intento mandarlo por ajax, logré cachar mis datos en el servidor, pero usando un form de razor.

@using (Html.BeginForm("BolsaDeTrabajoContacto", "Test", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<div class="form-row">
  <div class="form-group col-md-6">
    <input type="text" name="name" class="form-control" id="name_bolsa" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" value="x" required />
    <div class="validation"></div>
  </div>
  <div class="form-group col-md-6">
    <input type="email" class="form-control" name="email" id="email_bolsa" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" required value="[email protected]" />
    <div class="validation"></div>
  </div>
</div>
<div class="form-group">
  <input type="text" class="form-control" name="subject" id="subject_bolsa" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" required value="subbbb" />
  <div class="validation"></div>
</div>
<input type="file" id="file_bolsa" name="files" value="" required/>
<div class="form-group">
  <textarea class="form-control" id="message_bolsa" rows="5" data-rule="required" name="message" data-msg="Please write something for us" placeholder="Message" required>jiss</textarea>
  <div class="validation"></div>
</div>
<div class="text-center">
  <button class="btn btn-success" type="submit">Enviar</button>
</div>
}

Este es el mismo formulario que estaba usando para cachar con el ajax.

Alguien sabe a que se podría deber?

Alguien sabe a que se podría deber?

ok todo lo anterior persiste si intento mandarlo por ajax, logré cachar mis datos en el servidor, pero usando un form de razor.

@using (Html.BeginForm("BolsaDeTrabajoContacto", "Test", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<div class="form-row">
  <div class="form-group col-md-6">
    <input type="text" name="name" class="form-control" id="name_bolsa" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" value="x" required />
    <div class="validation"></div>
  </div>
  <div class="form-group col-md-6">
    <input type="email" class="form-control" name="email" id="email_bolsa" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" required value="[email protected]" />
    <div class="validation"></div>
  </div>
</div>
<div class="form-group">
  <input type="text" class="form-control" name="subject" id="subject_bolsa" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" required value="subbbb" />
  <div class="validation"></div>
</div>
<input type="file" id="file_bolsa" name="files" value="" required/>
<div class="form-group">
  <textarea class="form-control" id="message_bolsa" rows="5" data-rule="required" name="message" data-msg="Please write something for us" placeholder="Message" required>jiss</textarea>
  <div class="validation"></div>
</div>
<div class="text-center">
  <button class="btn btn-success" type="submit">Enviar</button>
</div>
}

Este es el mismo formulario que estaba usando para cachar con el ajax.

Alguien sabe a que se podría deber?

se añadieron 299 caracteres en el cuerpo
Origen Enlace
    event.preventDefault();
    var name = $('#name_bolsa').val();
    var email = $('#email_bolsa').val();
    var message = $('#message_bolsa').val();
    var subject = $('#subject_bolsa').val();

    var input = document.getElementById("file_bolsa");
    var files = input.files;
  
     //var data = new FormData();
/*
    for (var i = 0; i < files.length; i++) {

        data.append(files[i].name, files[i]);

    }
    */
    var data = {
        name: name,
        email: email,
        message: message,
        subject: subject,
        files :files
    };

  
   // data.files = files;

    console.log(data);

    $.ajax({
        url: "/test/BolsaDeTrabajoContacto",
        type: "POST",
        dataType: "text",
        //processData: false,
        //contentType: false,
        //contentType: "application/json; charset=utf-8",
        data: data,
        success: function (response) {

            //alert('ok'+res);
            //console.log(table);
            //console.log(JSON.stringify(table));
            console.log(response);
            alert(response);
        },

Entonces hasta ahora me manda el siguiente error:

TypeError: 'item' called on an object that does not implement interface FileList.

SI uso processData: false, contentType: false, El error desaparece, pero cuando veo formdata.files llega null

    event.preventDefault();
    var name = $('#name_bolsa').val();
    var email = $('#email_bolsa').val();
    var message = $('#message_bolsa').val();
    var subject = $('#subject_bolsa').val();

    var input = document.getElementById("file_bolsa");
    var files = input.files;
  
     //var data = new FormData();
/*
    for (var i = 0; i < files.length; i++) {

        data.append(files[i].name, files[i]);

    }
    */
    var data = {
        name: name,
        email: email,
        message: message,
        subject: subject
    };

  
   // data.files = files;

    console.log(data);

    $.ajax({
        url: "/test/BolsaDeTrabajoContacto",
        type: "POST",
        dataType: "text",
        //processData: false,
        //contentType: false,
        //contentType: "application/json; charset=utf-8",
        data: data,
        success: function (response) {

            //alert('ok'+res);
            //console.log(table);
            //console.log(JSON.stringify(table));
            console.log(response);
            alert(response);
        },
    event.preventDefault();
    var name = $('#name_bolsa').val();
    var email = $('#email_bolsa').val();
    var message = $('#message_bolsa').val();
    var subject = $('#subject_bolsa').val();

    var input = document.getElementById("file_bolsa");
    var files = input.files;
  
     //var data = new FormData();
/*
    for (var i = 0; i < files.length; i++) {

        data.append(files[i].name, files[i]);

    }
    */
    var data = {
        name: name,
        email: email,
        message: message,
        subject: subject,
        files :files
    };

  
   // data.files = files;

    console.log(data);

    $.ajax({
        url: "/test/BolsaDeTrabajoContacto",
        type: "POST",
        dataType: "text",
        //processData: false,
        //contentType: false,
        //contentType: "application/json; charset=utf-8",
        data: data,
        success: function (response) {

            //alert('ok'+res);
            //console.log(table);
            //console.log(JSON.stringify(table));
            console.log(response);
            alert(response);
        },

Entonces hasta ahora me manda el siguiente error:

TypeError: 'item' called on an object that does not implement interface FileList.

SI uso processData: false, contentType: false, El error desaparece, pero cuando veo formdata.files llega null

Origen Enlace
Loading