我正在尝试通过表单的action属性的url传递javascript变量。它看起来像:
<script type="text/javascript">
var imagefile =document.getElementById("imageBox").value;
</script>`
html表格:
<form action="http://myLocation/uploadServer.php?image="+file method="post" enctype="multipart/form-data" onsubmit="startUpload();" >
Upload New Image: <input name="myfile" type="file" id="imageBox" />
<input type="submit" name="submitBtn" value="Upload" onclick=""/>
</form>
它被重定向到目标页面, file 中没有任何内容。
甚至可能我正在尝试做什么?
答案 0 :(得分:0)
可以使用jQuery POST http://api.jquery.com/jQuery.post/
$('form').submit(function(e) {
e.preventDefault(); // stops form from being submitted via the button as normal
// now we post to the dynamic url
$.post('http://myLocation/uploadServer.php?image='+file, function(data) {
//success
});
});
服务器端的东西你还需要弄清楚..
答案 1 :(得分:0)
为什么不使用正确的form
?
<form action="http://myLocation/uploadServer.php"
method="post"
enctype="multipart/form-data"
onsubmit="startUpload();" >
Upload New Image: <input name="image" type="file" id="imageBox" />
<input type="submit" name="submitBtn" value="Upload" onclick=""/>
</form>