以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- js创建表单无法提交到网页 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=189492) |
||||
-- 作者:星瀚 -- 发布时间:2023/12/5 16:02:00 -- js创建表单无法提交到网页 js创建表单和元素值,提交到指定网页,console显示提交成功,但网页显示未收到数据,求解,谢谢! function
uploadRec() { var
xhr
=
new
XMLHttpRequest(); xhr.onreadystatechange
=
function() { if (xhr.readyState
===
XMLHttpRequest.DONE) { if (xhr.status
===
200) { console.log(\'Form submitted successfully\'); console.log(xhr.responseText); console.log(input1.name+input1.value); location
=
"accept.htm"; } else { console.log(\'Failed to submit form\'); } } }; var
form1
=
document.createElement(\'form\'); form1.method
=
\'POST\'; form1.action
=
\'accept.htm\'; var
input1
=
document.createElement(\'input\'); input1.type
=
\'text\'; input1.name
=
\'责任人\'; input1.value
=
\'John\'; var
input2
=
document.createElement(\'input\'); input2.type
=
\'text\'; input2.name
=
\'责任单位\'; input2.value
=
\'123456\'; form1.appendChild(input1); form1.appendChild(input2); xhr.open(\'POST\', form1.action,true); xhr.setRequestHeader("Content-Type","text/plain;charset=utf-8"); xhr.send(new
FormData(form1)); } |
||||
-- 作者:有点蓝 -- 发布时间:2023/12/5 16:21:00 -- 打开浏览器开发者工具,看看网络页面提交的是什么数据? 服务端是怎么接收数据的?
|
||||
-- 作者:星瀚 -- 发布时间:2023/12/5 16:47:00 -- 网页提交数据截图如下: 服务端
代码如下,项目请见附件,谢谢! Case "uploadpic.htm" Dim wb As New weui If e.PostValues.Count = 0 Then wb.AddForm("", "form1", "accept.htm") With wb.AddInputGroup("form1", "ipg22", "文件上传") \'带图片浏览的文件上传 With .AddUploader("up2", "图片", True) \'True表示允许一次上传多个文件 .AddImage("./images/001.jpg") .AddImage("./images/002.jpg") End With End With With wb.AddButtonGroup("form1", "btg2", True) .Add("btn1", "ajax上传", "button").Attribute = "" \'调用js函数上传 End With wb.AppendHTML("<script src=\'./lib/ajaxform.js\'></script>") \'引入脚本文件 e.WriteString(wb.Build) For Each key As String In e.Files.Keys For Each fln As String In e.Files(key) e.SaveFile(key, fln, "d:\\web\\uploadfiles\\" & fln) \'保存接收到的文件 Next Next e.WriteString(wb.Build) End If Case "accept.htm" Dim sb As New StringBuilder For Each key As String In e.Files.Keys sb.AppendLine(key & " 上传" & e.Files(key).Count & "个文件,分别是:</br>") For Each fle As String In e.Files(key) sb.AppendLine(fle & "<br>") e.SaveFile(key, fle, "d:\\web\\uploadfiles\\" & fle) \'保存接收到的文件 Next sb.AppendLine("</br>") Next sb.AppendLine("接收到的数据有:<br/><br/>") For Each key As String In e.Values.Keys sb.AppendLine(key & ":" & e.Values(key) & "<br/>") Next sb.AppendLine("</br>") sb.AppendLine("以上文件服务器已正确接收并保存!") e.WriteString(sb.ToString) |
||||
-- 作者:有点蓝 -- 发布时间:2023/12/5 17:27:00 --
|