自己写的AjaxForm

$.extend({
    AjaxForm: function (action, formID, callback) {
        var form = $("#" + formID);
        form.attr("action", action);
        form.attr("method", "post");
        $("#callbackmethod").remove();
        form.append("<input id='callbackmethod' name='callbackmethod' type='hidden' value='" + callback + "' \>");
        var ajaxiframe = formID + "_AjaxIFrame";
        form.attr("target", ajaxiframe);
        form.append("<iframe name='" + ajaxiframe + "' id='" + ajaxiframe + "' style='display:none;'></iframe>");
        form.attr("enctype", "multipart/form-data");
        form.submit();

    },
    ToJson: function (str) {
        return eval('(' + str + ')');
    }
});


 

$.AjaxForm('<%=Url.Content("~/Utility/PicUploadHander.ashx")%>', 'UpLoadForm', function (str) {
                var json = eval('(' + str + ')');
                alert(json.Name);
                parent.Home();//主页面的方法
            }); 

 

 private void WriteForm(string str, HttpContext context)
        {
            string method = context.Request["callbackmethod"];
            string isJson = context.Request["isJson"];
            string hs = "<script> void " + method + " ('" + str + "');</script>";
            context.Response.Write(hs);
            context.Response.Flush();
            context.Response.Close();
        } 

 

 

 

 

 

posted @ 2010-11-21 15:07  [秦时明月]  阅读(708)  评论(0编辑  收藏  举报