Javascript 在kentico中使用response.write重定向html表单无效
我试图将HTML表单发布到另一个URL,在我的测试中,表单被创建:Javascript 在kentico中使用response.write重定向html表单无效,javascript,c#,asp.net,http-post,kentico,Javascript,C#,Asp.net,Http Post,Kentico,我试图将HTML表单发布到另一个URL,在我的测试中,表单被创建: <html> <body onload='document.forms["form1"].submit()'> <form id='form1' method='POST' action='http://localhost:52035/testpage?'> <input type='hidden' id='name' value='form1' /> <input type
<html>
<body onload='document.forms["form1"].submit()'>
<form id='form1' method='POST' action='http://localhost:52035/testpage?'>
<input type='hidden' id='name' value='form1' />
<input type='hidden' name='NEW_ITEM["0"] value='1234-ABC'/>
</form>
</body>
</html>
- 如果你只是搜索一下,这个问题已经很多了
- 您缺少新商品的结束报价…
- 第三,使用Ajax+FormData,而不是与html混为一谈
这里有一个可能解决你问题的方法
document.forms.form1.submit()
我没有提到我的代码在ascx页面中,我将代码移动到了aspx页面,然后响应。write now将表单数据发送到外部URL。你的表单没有name=“form1”
。哦,这应该在加载
后执行。嗨,帕文,我添加了name='form1',你是说htmlForm行吗“”需要更改?没有好友,onload
,未看到
。添加name='form1'后,仍然无法工作。已解决。我现在将数据发送到aspx代码隐藏页,然后构建表单并从那里发布。
protected void btnSubmitRequest_Click(object sender, EventArgs e)
{
var hookUrl = SessionHelper.GetValue("hookurl").ToString();
string formId = "form1";
StringBuilder htmlForm = new StringBuilder();
htmlForm.AppendLine("<html>");
htmlForm.AppendLine(String.Format("<body onload='document.forms[\"{0}\"].submit()'>", formId));
htmlForm.AppendLine(String.Format("<form id='{0}' method='POST' action='{1}'>", formId, hookUrl));
htmlForm.AppendLine("<input type='hidden' id='name' value='form1' />");
// test values
prod.ProductCode = "1234-ABC"
int i = 0;
htmlForm.AppendLine(String.Format("<input type='hidden' name='NEW_ITEM[\"{0}\"] value='{1}'/>",i, prod.ProductCode));
htmlForm.AppendLine("</form>");
htmlForm.AppendLine("</body>");
htmlForm.AppendLine("</html>");
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(htmlForm.ToString());
HttpContext.Current.ApplicationInstance.CompleteRequest();
}