Javascript 如何将带有输入图像的表单提交到模式引导中?
我有一个使用Javascript 如何将带有输入图像的表单提交到模式引导中?,javascript,php,jquery,forms,twitter-bootstrap,Javascript,Php,Jquery,Forms,Twitter Bootstrap,我有一个使用bootstrap的模式表单。表单包含一些文本输入和图像输入 我用ajax提交表单,所有数据都在PHP文件中正确接收。唉,图像没有上传 我的代码有什么问题 <script> $(document).ready(function () { $("input#submit").click(function(){ $.ajax({ type: "POST", url:
bootstrap
的模式表单
。表单包含一些文本输入和图像输入
我用ajax提交表单,所有数据都在PHP
文件中正确接收。唉,图像没有上传
我的代码有什么问题
<script>
$(document).ready(function () {
$("input#submit").click(function(){
$.ajax({
type: "POST",
url: "insert.php",
data: $('form.contact').serialize(),
success: function(msg){
$("#th").html(msg)
$("#form-content").modal('hide');
$("#pro").html(content);
},
error: function(){
alert("failure");
}
});
});
});
</script>
$(文档).ready(函数(){
$(“输入#提交”)。单击(函数(){
$.ajax({
类型:“POST”,
url:“insert.php”,
数据:$('form.contact')。序列化(),
成功:功能(msg){
$(“#th”).html(msg)
$(“#表单内容”).modal('hide');
$(“#pro”).html(内容);
},
错误:函数(){
警报(“故障”);
}
});
});
});
表格:
<form class="contact" name="contact" enctype="multipart/form-data">
<label for="inputNombre" class="sr-only">Título</label>
<input id="inputNombre" name="inputNombre" class="form-control" placeholder="Título" required="TRUE" autofocus="" type="text">
<br>
....
<div class="upload_pic1 inline">
<input id="imagen" name="imagen" type="file">
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cerrar</a>
<input id="submit" class="btn btn-success" type="submit" value="Crear">
</div>
</div>
</form>
蒂图罗
....
编辑:
insert.php
<?php
session_start();
if (!isset($_SESSION["name"]) && $_SESSION["name"] == "") {
// user already logged in the site
header("location: Login.html");
}
require_once('funt.php');
conectar('localhost', 'root', '', 'db');
if (isset($_POST['inputNombre'])) {
$nombre = strip_tags($_POST['inputNombre']);
....
//Here the var imagen
if(is_uploaded_file($_FILES['imagen']['tmp_name'])){
$rutaEnServidor='imagenes';
$rutaTemporal=$_FILES['imagen']['tmp_name'];
$nombreImagen=$_FILES['imagen']['name'];
$rutaDestino=$rutaEnServidor.'/'.$nombreImagen;
move_uploaded_file($rutaTemporal,$rutaDestino);
} else { //Always enter here, so is not uploaded
$rutaEnServidor='imagenes';
$rutaTemporal='/noPicture.png';
$rutaDestino=$rutaEnServidor.'/noPicture.png';
move_uploaded_file($rutaTemporal,$rutaDestino);
}
...
您可以使用。然后,您必须告诉jQuery不要设置内容类型,也不要处理数据
首先检查FormData
构造函数的兼容性表。这可能就足够了
否则,请通读本讨论。您是否将$\u文件转储到superglobal以查看它得到了什么?如果temp
为空,则目录权限可能存在一些问题。是否有名为insert.php
的脚本?如果是的话,给我们看看。如果没有,那么你需要写一个。对不起,我忘了这个,我已经编辑并显示了这个。谢谢