Get the App
SLTechnology News&Howtos  ›  Development  › 

How Ajax does not refresh the Url submission page

Shulou Source: shulou.com Published: 2022-06-03 06:01:15 11月17日 Update

This article will explain in detail how Ajax does not refresh the Url submission page. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

With the popularity of frameworks such as Jquery,porotype,Ext, a lot of simplified code can be said to be a boon for programmers.

Freed from the heavy code work, it is easy to achieve the complex functions of writing in the past.

However, there are pros and cons. Up to now, programmers who are used to using various frameworks and seldom write their own internal source code still have a few basic codes that remember Ajax that are not really complex.

In order not to forget my original enthusiasm, I re-posted this basic code and reviewed it for myself.

one. For Ajax, determining the categories of browsers is a repetitive and nothing new task, and this code can be encapsulated and called at will.

The code is as follows:

Function xmlhttp ()

{

Var A=null

Try

{

A=new ActiveXObject ("Msxml2.XMLHTTP")

}

Catch (e)

{

Try

{

A=new ActiveXObject ("Microsoft.XMLHTTP")

}

Catch (oc)

{

If (typeof XMLHttpRequestrated = "Undefined")

{

A=new XMLHttpRequest ()

}

}

}

Return A

}

Do not explain, anyway, even if do not understand, directly copy the past is no problem.

two. Next is the code that submits the Url.

The whole process is more or less the same, most of the code can actually be encapsulated, as long as the parameters are passed in, and then get the result.

The code is as follows:

Function Ajax (url)

{

Var XmlHttp=new xmlhttp ()

Try

{

XmlHttp.open ("POST", url,true)

Var result=SendUrl ()

}

Catch (e)

{

Alert (e)

}

}

3.

The code is as follows:

Function SendUrl ()

{

XmlHttp.send ()

XmlHttp.onreadystatechange=function ()

{

If (XmlHttp.readyState==4 & & XmlHttp.status==200)

{

Var result=XmlHttp.responseText

Return result

}

}

}

This is the end of the article on "how Ajax does not refresh the Url submission page". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Code articles pages complexity more frameworks programs programmers encapsulation work good practical onerous enthusiastic more or less the same and then pros and cons content function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Apple Shulou Information MariaDB