1
In doing .ajaxSubmit()
of a form with a input type="file"
I always get the error:
Uncaught Typeerror: jQuery(...). data(...) is not a Function
Form:
@using (Html.BeginForm("guardarDocComprovaticoProdOSCli", "OrdemServicos_Clientes", FormMethod.Post, new { id = "formSaveFile", enctype = "multipart/form-data" }))
{
<input type="file" name="filepath" id="filepath" />
<br />
}
JS function:
function guardarDocComprovaticoProdOSCli() {
if ($('#filepath').val() != "") {
$("#formSaveFile").ajaxSubmit({
type: "POST",
data: { idProdutoOSCli: window.idProdutoOSCli },
success: function (result) {
alert(result);
$('#myModal').modal('hide');
},
error: function (a, b, c) {
alert(b);
alert(c);
}
});
}
}
Controller:
[AcceptVerbs(HttpVerbs.Post)]
public JsonResult guardarDocComprovaticoProdOSCli(int idProdutoOSCli)
{
HttpPostedFileBase filepath = (HttpPostedFileBase)Request.Files[0];
var nameFile = "" + idProdutoOSCli + "_AnexoComprovatioProdOSCli_" + filepath.FileName + "";
...
return Json("Doc. carregado", JsonRequestBehavior.AllowGet);
}
I get this error before going to function on Controller, where everything passes correctly and works everything (save file, among other tasks I am doing). But how I wanted to use the success
I have this problem... No error
of .ajaxSubmit()
also does not contain relevant information.
Cesar, the problem is in this very role?
– Renan Gomes
Yes @Renan. That’s right when I click a button to call the function
guardarDocComprovaticoProdOSCli()
– CesarMiguel
Which jQuery version is using?
– Guilherme Nagatomo
@Guilhermenagatomo 1.10.3
– CesarMiguel
This is looking more like a missing jquery library error.
– Ivan Ferrer