[英]How can I submit a form from another page with existing data?
Edit: I understand that its probably easiest to use jQuery's built in ajax function here, but my question now is about the names that the form is using for its fields. 编辑:我知道它可能最容易在这里使用jQuery的内置ajax函数,但是我现在的问题是有关表单用于其字段的名称。 This is a var_dump of what the form usually submits using test values.
这是表单通常使用测试值提交的内容的var_dump。 It seems to be randomly generating the form names which makes this problematic.
它似乎是随机生成的表单名称,这使此问题。
array (size=10)
'__CSRFToken__' => string '3bc67b3ea7645150d346c3db476c53a94ceee80e' (length=40)
'a' => string 'open' (length=4)
'topicId' => string '12' (length=2)
'4d46ff92be4bf2f9' => string 'test' (length=4)
'b6679eba951ccafb' => string 'test' (length=4)
'de756c0f51c9b255' => string '' (length=0)
'de756c0f51c9b255-ext' => string '' (length=0)
'099ed5bd56c915a1' => string 'test' (length=4)
'message' => string 'Test' (length=4)
'draft_id' => string '4' (length=1)
On one of my web pages has users enter information to fill a ticket form. 用户在我的网页之一上输入信息以填写票证表格。 I am using osTicket to manage them but I am collecting the information on a separate page for certain reasons.
我正在使用osTicket来管理它们,但是由于某些原因,我正在另一页上收集信息。 Suppose I have all of the information stored in a Javascript object,
假设我已将所有信息存储在Javascript对象中,
var ticket = {
name : "John Snow",
email : "test@gmail.com",
summary: "xxx",
body: "xxxx"
};
for example, how could I go about getting that information to the form on the other page ( picture below ) and submit it? 例如,我如何才能将该信息获取到另一页上的表单(下图)中并提交?
You could use ajax with something like this: 您可以将ajax与以下内容一起使用:
var xhReq = new XMLHttpRequest();
xhReq.open("GET", "page.php?name=name&emailemail&etc...", false);
xhReq.send(null);
var serverResponse = xhReq.responseText;
alert(serverResponse); // Shows "15"
You should read this for a better explanation AJAX 您应该阅读此内容以获得更好的解释AJAX
You can submit form by various methods by using html form tag ,jquery etc.I m giving example with jquery. 您可以使用html表单标签,jquery等通过各种方法提交表单。我以jquery为例。 Script:
脚本:
$('#submitButn').click(function () {
$.ajax({
url: "/Home/Index", //url for your page,
type: "POST",
data: dataToPost //you data which u want to post
success: function (data, status) {
},
error: function (xhr, desc, err) {
alert("error");
},
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.