如何在ajax图像上传中将变量从index.php发送到ajaximage.php?(How to send variables from index.php to ajaximage.php in ajax image uploading?)
我需要将用户logid和输入ID发送到服务器以及使用jquery上传的图像。 我发送的只是图像。 这是我目前的代码:index.php
<?php include('db.php'); session_start(); $session_id='1'; //$session id ?> <script type="text/javascript" src="scripts/jquery.min.js"></script> <script type="text/javascript" src="scripts/jquery.form.js"></script> <script type="text/javascript" > $(document).ready(function() { $('.photoimg').live('change', function() { var id=$(this).attr("id"); var split=id.split("photoimg"); var splited=split[1]; alert(splited); $("#preview").html(''); $("#preview").html('<img src="loader.gif" alt="Uploading...."/>'); $("#imageform").ajaxForm({ target: '#preview' }).submit(); }); }); </script> <form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'><br> Upload your image1 <input type="file" name="photoimg" id="photoimg1" class="photoimg"/><br> Upload your image2 <input type="file" name="photoimg" id="photoimg2" class="photoimg"/><br> Upload your image3 <input type="file" name="photoimg" id="photoimg3" class="photoimg"/><br> </form> <div id='preview'> </div>请帮忙
I need to send users logid and input id to server along with image uploaded with jquery. Only thing i get to send is image. Here is my current code: index.php
<?php include('db.php'); session_start(); $session_id='1'; //$session id ?> <script type="text/javascript" src="scripts/jquery.min.js"></script> <script type="text/javascript" src="scripts/jquery.form.js"></script> <script type="text/javascript" > $(document).ready(function() { $('.photoimg').live('change', function() { var id=$(this).attr("id"); var split=id.split("photoimg"); var splited=split[1]; alert(splited); $("#preview").html(''); $("#preview").html('<img src="loader.gif" alt="Uploading...."/>'); $("#imageform").ajaxForm({ target: '#preview' }).submit(); }); }); </script> <form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'><br> Upload your image1 <input type="file" name="photoimg" id="photoimg1" class="photoimg"/><br> Upload your image2 <input type="file" name="photoimg" id="photoimg2" class="photoimg"/><br> Upload your image3 <input type="file" name="photoimg" id="photoimg3" class="photoimg"/><br> </form> <div id='preview'> </div>Please help
最满意答案
您可以将参数添加到表单的操作,如下所示:
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php?logid=XXX'>或者如果var是PHP可能:
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php?logid=<?php echo $logId;?>'>然后在ajaximage.php中处理它:
$_GET['logid']Can you add the parameters to the action of the form as follows:
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php?logid=XXX'>or if the var is PHP which is likely:
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php?logid=<?php echo $logId;?>'>and then process it in ajaximage.php with:
$_GET['logid']更多推荐
发布评论