ajaxSubmit和其他代码。有人可以帮我确定这段代码在做什么吗?

时间:2022-12-18 01:33:07

I've inherited some code that I need to debug. It isn't working at present. My task is to get it to work. No other requirements have been given to me. No, this isn't homework, this is a maintenance nightmare job.

我继承了一些我需要调试的代码。它目前无效。我的任务是让它发挥作用。没有给我任何其他要求。不,这不是家庭作业,这是一项维护噩梦般的工作。

ASP.Net (Framework 3.5), C#, jQuery 1.4.2. This project makes heavy use of jQuery and AJAX. There is a drop down on a page that, when an item is chosen, is supposed to add that item (it's a user) to an object in the database.

ASP.Net(Framework 3.5),C#,jQuery 1.4.2。这个项目大量使用jQuery和AJAX。页面上有一个下拉列表,当选择一个项目时,应该将该项目(它是用户)添加到数据库中的对象。

To accomplish this, the previous programmer first, on page load, dynamically loads the entire page through AJAX. To do this, he's got 5 div's, and each one is loaded from a jQuery call to a different full page in the website.

为了实现这一点,先前的程序员首先在页面加载时通过AJAX动态加载整个页面。为此,他有5个div,每个都从jQuery调用加载到网站的不同整页。

Somehow, the HTML and BODY and all the other stuff is stripped out and the contents of the div are loaded with the content of the aspx page. Which seems incredibly wrong to me since it relies on the browser to magically strip out html, head, body, form tags and merge with the existing html head body form tags.

不知何故,HTML和BODY以及所有其他内容被剥离,div的内容加载了aspx页面的内容。这对我来说似乎非常错误,因为它依赖于浏览器神奇地删除html,head,body,form标签并与现有的html head body form标签合并。

Also, as the "content" page is returned as a string, the previous programmer has this code running on it before it is appended to the div:

此外,当“content”页面作为字符串返回时,之前的程序员在将其附加到div之前会运行此代码:

function CleanupResponseText(responseText, uniqueName) {
    responseText = responseText.replace("theForm.submit();", "SubmitSubForm(theForm, $(theForm).parent());");
    responseText = responseText.replace(new RegExp("theForm", "g"), uniqueName);
    responseText = responseText.replace(new RegExp("doPostBack", "g"), "doPostBack" + uniqueName);
    return responseText;
}

When the dropdown itself fires it's onchange event, here is the code that gets fired:

当下拉列表本身触发它的onchange事件时,这里是被触发的代码:

function SubmitSubForm(form, container) {
    //ShowLoading(container);
    $(form).ajaxSubmit( {
                url: $(form).attr("action"),
                success: function(responseText) {
                    $(container).html(CleanupResponseText(responseText, form.id));
                    $("form", container).css("margin-top", "0").css("padding-top", "0");
                    //HideLoading(container);
                }
            }
        );
    }

This blows up in IE, with the message that "Microsoft JScript runtime error: Object doesn't support this property or method" -- which, I think, has to be that $(form).ajaxSubmit method doesn't exist.

这在IE中爆发,消息“Microsoft JScript运行时错误:对象不支持此属性或方法” - 我认为,这必须是$(form).ajaxSubmit方法不存在。

What is this code really trying to do? I am so turned around right now that I think my only option is to scrap everything and start over. But I'd rather not do that unless necessary.

这段代码真正想要做什么?我现在转过身来,我认为我唯一的选择是废弃一切并重新开始。但除非必要,否则我宁愿不这样做。

Is this code good? Is it working against .Net, and is that why we are having issues?

这段代码好吗?它是否适用于.Net,这就是我们遇到问题的原因吗?

2 个解决方案

#1


0  

A google search for

谷歌搜索

jquery ajax submit

jquery ajax提交

reveals the jQuery Form Plugin. Given that, is that file included on your page where the other code will have access to the method? Does this code work in Firefox and not IE?

揭示了jQuery Form Plugin。鉴于此,您的页面上是否包含其他代码可以访问该方法的文件?此代码是否适用于Firefox而不是IE?

#2


0  

Seems like there was too much jQuery fun going on. I completely reworked the entire code block since it was poorly designed in the first place.

似乎有太多的jQuery乐趣正在进行中。我完全重写了整个代码块,因为它首先设计得很糟糕。

#1


0  

A google search for

谷歌搜索

jquery ajax submit

jquery ajax提交

reveals the jQuery Form Plugin. Given that, is that file included on your page where the other code will have access to the method? Does this code work in Firefox and not IE?

揭示了jQuery Form Plugin。鉴于此,您的页面上是否包含其他代码可以访问该方法的文件?此代码是否适用于Firefox而不是IE?

#2


0  

Seems like there was too much jQuery fun going on. I completely reworked the entire code block since it was poorly designed in the first place.

似乎有太多的jQuery乐趣正在进行中。我完全重写了整个代码块,因为它首先设计得很糟糕。