Javascript ajax插入是否可以在不使用async:false的情况下按正确顺序执行?

Javascript ajax插入是否可以在不使用async:false的情况下按正确顺序执行?,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,在我的ASP.NETMVC页面上,我有一个AJAX表单 @using (Ajax.BeginForm("action", "controller", new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.InsertAfter, UpdateTargetId = "target" })) { //form in here

在我的ASP.NETMVC页面上,我有一个AJAX表单

@using (Ajax.BeginForm("action", "controller", new AjaxOptions {
        HttpMethod = "POST",
        InsertionMode = InsertionMode.InsertAfter,
        UpdateTargetId = "target"
    }))
    {
            //form in here
            <input name="foo">
            //...
    }
@使用(Ajax.BeginForm(“操作”、“控制器”、新的AjaxOptions{
HttpMethod=“POST”,
InsertionMode=InsertionMode.InsertAfter,
UpdateTargetId=“目标”
}))
{
//在这里形成
//...
}
用户可以输入数据并手动提交表单,也可以复制大量数据并一次性提交。我使用下面的JS来实现这一点

jQuery.ajaxSetup({ async: false });
var objects = getDataFromClipboard();
for (x = 0; x < objects.length; x++) {
    $('#foo').val(objects[x]);
    $('#form').submit();
}
jQuery.ajaxSetup({ async: true });
jQuery.ajaxSetup({async:false});
var objects=getDataFromClipboard();
对于(x=0;x
问题是,我被迫使用“async:false”,这非常慢,在工作时会冻结整个页面。如果我保留“async:true”,那么结果将以错误的顺序追加


有没有更快的方法来强制这些表单按顺序执行更新?

感谢Rory McCrossan为我指明了正确的方向

一个非常简单的解决方案是将所有输入分组为一个字符串,用分隔符分隔。然后我可以简单地在一个请求中发送整个数据。我只需要重写控制器来处理这个输入

我改变了我的JS如下:

var objects = getDataFromClipboard();
var foo = objects[0];
for (x = 1; x < objects.length; x++) {
    foo = foo + "|" + objects[x];
}
$('#foo').val(foo);
$('#form').submit();
形式

@使用(Ajax.BeginForm(“操作”、“控制器”、新的AjaxOptions{
HttpMethod=“POST”,
InsertionMode=InsertionMode.InsertAfter,
UpdateTargetId=“目标”
}))
{
//在这里形成
//...
}
我的控制器现在处理输入,如下所示

[HttpPost]
public ActionResult action(ADModel model)
{
    char separator = "|"[0];
    if (!String.IsNullOrEmpty(model.foo))
    {
        string[] foos = model.fname.Split(separator);
        string result = "";
        for (int x = 0; x < foos.Length; x++)
        {
            result = result + searchData(foo[x]) + "<br>";
        }
        return Content(result, "text/html");
    } else {
        return Content("<i>No results found</i>","text/html");
    }
}
[HttpPost]
公共行动结果行动(ADModel模型)
{
字符分隔符=“|”[0];
如果(!String.IsNullOrEmpty(model.foo))
{
字符串[]foos=model.fname.Split(分隔符);
字符串结果=”;
对于(int x=0;x”;
}
返回内容(结果,“文本/html”);
}否则{
返回内容(“未找到结果”、“文本/html”);
}
}

两种可能性;首先,链接请求。其次,将所有数据放在一个请求中并发送。到目前为止,后者是最好的选择。忽略任何建议
async:false
@RoryMcCrossan处理输入的控制器/模型设置为使用单个值(字符串)的人。我仍然可以在一个请求中发送所有数据,还是需要重写这些数据以接受/返回数组?是的,您需要重写这些端点的模型。感谢您为我指明了正确的方向。我更改了所有内容,以便在单个请求中发送数据,它的性能更好,并且不会冻结我的页面。我把它贴在下面作为答案。
@using (Ajax.BeginForm("action", "controller", new AjaxOptions {
    HttpMethod = "POST",
    InsertionMode = InsertionMode.InsertAfter,
    UpdateTargetId = "target"
}))
{
        //form in here
        <input name="foo">
        //...
}
[HttpPost]
public ActionResult action(ADModel model)
{
    char separator = "|"[0];
    if (!String.IsNullOrEmpty(model.foo))
    {
        string[] foos = model.fname.Split(separator);
        string result = "";
        for (int x = 0; x < foos.Length; x++)
        {
            result = result + searchData(foo[x]) + "<br>";
        }
        return Content(result, "text/html");
    } else {
        return Content("<i>No results found</i>","text/html");
    }
}