javascript

位置:IT落伍者 >> javascript >> 浏览文章

.Net环境下基于Ajax的MVC方案[2]


发布日期:2021年01月25日
 
.Net环境下基于Ajax的MVC方案[2]
部分范例源码

Defaultaspx

<%@Pagelanguage=c#Codebehind=DefaultaspxcsAutoEventWireup=falseInherits=CNTeddyAjaxHelperWebForm%>

<!DOCTYPEHTMLPUBLIC//WC//DTDHTMLTransitional//EN>

<HTML>

<HEAD>

<title>WebForm</title>

<metaname=GENERATORContent=MicrosoftVisualStudioNET>

<metaname=CODE_LANGUAGEContent=C#>

<metaname=vs_defaultClientScriptcontent=JavaScript>

<metaname=vs_targetSchemacontent=http://schemasmicrosoftcom/intellisense/ie>

<scripttype=text/javascriptlanguage=javascriptsrc=js/AjaxHelperjs></script>

</HEAD>

<body>

<formid=Formmethod=postrunat=server>

<divid=view>loading</div>

<scripttype=text/javascript>

Updater(AjaxTemplate/GetPageSrcviewurl=http://wwwcnblogscom);

</script>

</form>

</body>

</HTML>

AjaxHelperjs摘要

varAjaxHelperUrl=newString(Ajaxaspx);

varUpdater=function(ajaxTemplateoutputparamsonComplete)

{

if(typeofoutput==string)

{

output=$(output);

}

newAjaxRequest(Ajaxaspx{onComplete:function(transport){if(output!=null){outputinnerHTML=FormatContent(transportresponseText);}if(onComplete!=null){onComplete(FormatContent(transportresponseText))}}parameters:params+&AjaxTemplate=+ajaxTemplate});

}

varSerializeForm=function(form)

{

returnFormserialize(form);

}

varFormatContent=function(str)

{

varcontent=newString(str);

varprefix=newString(<!AjaxContent>);

content=contentsubstring(contentindexOf(prefix)+prefixlengthcontentlength);

returncontent;

}

UserControl GetPageSrcascxcs摘要

privatevoidPage_Load(objectsenderSystemEventArgse)

{

lbUrlText=RequestForm[url];

SystemNetWebClientclient=newSystemNetWebClient();

clientHeadersAdd(UserAgentMozilla/(compatible;MSIE;WindowsNT;NETCLR));

try

{

txtPageSourceText=newSystemIOStreamReader(clientOpenRead(lbUrlText)SystemTextEncodingUTF)ReadToEnd();

}

catch(Exceptionex)

{

throwex;

}

}

[] []

               

上一篇:.Net 底下,Json 相关套件的限制

下一篇:.Net环境下基于Ajax的MVC方案[1]