Get the App
SLTechnology News&Howtos  ›  Development  › 

How to establish Ajax+PHP quickly

Shulou Source: shulou.com Published: 2022-06-03 06:57:14 10月04日 Update

This article mainly explains "how to establish Ajax+PHP quickly". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to build Ajax+PHP quickly".

Brief introduction:

Ajax consists of HTML, JavaScript ™technology, DHTML, and DOM, an excellent way to transform a clumsy Web interface into an interactive Ajax application.

For Ajax, the core object is XMLHttpRequest, and all Ajax operations are inseparable from the operation on this object.

Create a XMLHttpRequest object

For IE browsers:

The copy code is as follows:

XmlHttp = new ActiveXObject ('Microsoft.XMLHTTP')

For other browsers:

The copy code is as follows:

XmlHttp = new XMLHttpRequest ()

Different browsers have different support for XMLHttpRequest objects in javascript, so you need to make a judgment on a case-by-case basis.

XMLHttpRequest object related methods

Open request

The copy code is as follows:

XMLHttpRequest.open (delivery mode, address, whether or not asynchronous request)

Ready for execution

The copy code is as follows:

XMLHttpRequest.onreadystatechange

Get the execution result

The copy code is as follows:

XMLHttpRequest.responseText

A simple example of php+Ajax:

The first is the test.js file:

The copy code is as follows:

Var xmlHttp

Function S_xmlhttprequest () {

If (window.ActiveXObject) {

XmlHttp=new ActiveXObject ('Microsoft.XMLHTTP')

} else if (window.XMLHttpRequest) {

XmlHttp=new XMLHttpRequest ()

}

}

Function php100 (url) {

S_xmlhttprequest ()

XmlHttp.open ("GET", "do.php?id=" + url,true)

XmlHttp.onreadystatechange=byphp

XmlHttp.send (null)

}

Function byphp () {

Var byphp100=xmlHttp.responseText

Document.getElementById ('php100') [xss_clean] = byphp100

}

Then there is the file that performs the php operation, do.php

The copy code is as follows:

Tags: Code objects browsers learning browsing content situations files methods different outstanding clumsy interactive examples front ends addresses that is applications ideas technologies Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Shulou Information Microsoft Linux