开发者

ajaxSubmit and Other Code. Can someone help me determine what this code is doing?

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.

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.

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.

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:

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:

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.

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?


A google search for

jquery ajax submit

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜