使用ajax发布数据的问题 [英] problem with posting data with ajax

查看:86
本文介绍了使用ajax发布数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,将一些数据插入到数据库中,并带有图像文件上传

将图像网址保存到数据库后调整大小广告将图像保存到我的文件夹

这里是代码

i have a form that insert some data to a db with an image file upload
saving image url to db after i resize it ad save the image to my folder
here is the code

<form id="form_insert_edit" action="insert.php" method="post">
    <table dir="rtl" cellpadding="5" cellspacing="5" width="500px">
        <tr>
            <th valign='top' align='right'>name</th>
            <td><input type='text' name='name' id="name" /></td>
        </tr>
        <tr>
            <th valign='top' align='right'>job description</th>
            <td>
                <select name='pName' id="pName">
                <option value='0'></option>
                ...etc
                </select>
            </td>
        </tr>
        <tr>
            <th valign='top' align='right'>القسم</th>
            <td>
                <!--Fill the Departments-->                
                <select name='sectionNames' id="sectionNames">
                    <option value='0'>Fill Data From DB</option>
                </select>
            </td>
        </tr>
        <tr>
            <th valign='top' align='right'>ext no</th>
            <td align='right'><input type='text' name='pNo' id="pNo" /></td>
        </tr>
        <tr>
            <th align='right'>image</th>
            <td><input type='file' name='file' id="file" /></td>
        </tr>			 		 
        <tr>
            <td></td>
            <td>
                <input type='submit' id="ADD" name='ADD'  value='save' />    
                <input type='button' id="Cancel" name='Cancel'  value='cancel' />
            </td>
        </tr>
        <tr>
            <td>
                <span id="bottom"></span>
                <div id="divdate">
                	<?php 
					if(isset($_SESSION['user_name'])){
						echo $_SESSION['user_name'].' inserted successfully ';
					}
					?>
                </div>
                
            </td>
            <td></td>
        </tr>
    </table>
</form>





和我的js代码是





and my js code is

$(document).ready( function() {		
	$('#Editpopup').click( function(){				
		loadPopupBox();
		$("#name").focus();
	});
	function loadPopupBox() {    // To Load the Popupbox
		$('#popup').fadeIn("slow");
		$("#container").css({ // this is just for style
			"opacity": "0.3"  
		});         
	}
	
	$('#popupBoxClose').click( function() {            
		unloadPopupBox();
	});	
	$("#Cancel").click(function(){
		unloadPopupBox();
	});	
	function unloadPopupBox() {	// TO Unload the Popupbox
		$('#popup').fadeOut("slow");
		$("#container").css({ // this is just for style		
			"opacity": "1"  
		}); 
	}		
	
	/* Insert part */
	$("#ADD").click(function(){
		name=$("#name").val();
		pName=$("#pName").val();
		section=$("#sectionName").val();
		ext=$("#pNo").val();
                img=$("#file").val();
		$.ajax({
			type: "POST",
			url: "insert.php",
			data: "name="+name+"&pName="+pName+"§ion="+section+"&ext="+ext+"&img="+img,
			success: function(html){
				if(html=='true'){
					$("#divdate").html("Data Inserted Successfully");
				}else{
					$("#divdate").html("something wrong, please try later");
				}
			},
			beforeSend:function(){
				$("#divdate").html("Loading...")
			}
		});
		return false;
	});
});



i还需要上传图片我不能这样做



帮助不需要发布到insert.php的所有数据正确idk为什么


i need also to upload the image i could not do it like this

help needed not all data posted to insert.php correctly idk why

推荐答案

_SESSION [' user_name'])){
echo
_SESSION['user_name'])){ echo


_SESSION [ ' user_name']。' 已成功插入';
}
?>
< / div >

< / td >
< td > < / td >
< / tr >
< ; / table >
< / form >
_SESSION['user_name'].' inserted successfully '; } ?> </div> </td> <td></td> </tr> </table> </form>





和我的js代码是





and my js code is


document )。ready( function (){
(document).ready( function() {


这篇关于使用ajax发布数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆