AJAX uses post to send data in xml format and receive data
This article mainly introduces how AJAX uses post to send data in xml format and accepts data. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
AJAX uses post to send data xml. The format accepts data, friends who need it can refer to
Notes:
1. Use POST to send data, and the function on line 2 (also the function for ajax to send data: ajaxCall) must be added One sentence: xmlObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Then use xmlObject.send(data); to send
2.3 line Note on the function:
1. Disable caching (recommended, not necessary): header("Cache-Control:no-cache");
2. When using XML data format, you must add: header("Content-Type: text/xml; charset=gb2312");//Write XML here
3. If you use MYSQL installed in the WAMP5 integrated environment, when querying the database, you must add:
$charset = "gb2312";
mysql_query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary"); //This sentence is necessary to solve the problem of Chinese garbled encryption Problem s
Otherwise, the encryption will be garbled. I wasted a long time here today. I used the database installed by default in the ECSHOP GBK version.
4. If you use XML to receive data, callback function It must be processed separately for IE and non-IE, otherwise there will always be one party that cannot marry the XML data
The processing code is as follows:
function getXMLData(tagName)//获取XML数据,分IE和非IE处理 { var info; if(window.ActiveXObject) //IE取回XML文件方法 { var doc = new ActiveXObject("MSxml2.DOMDocument"); doc.loadXML(xmlObject.responseText); info = doc.getElementsByTagName(tagName); } else //---------------------------非IE取回XML文件方法 { info = xmlObject.responseXML.getElementsByTagName(tagName); } return info; }
The following is a province and city linkage test I did
The code is as follows:
index.php省事联动测试
chuli.php <?php//3号线header("Cache-Control:no-cache"); header("Content-Type: text/xml; charset=gb2312");//这里要写XML require("function.php"); $id = $_POST['id']; file_put_contents("my1.txt",$act . "------" . $ziduan); $result = getresultById($id); $info = "<mes>"; foreach($result as $row){$info .= "<res>"; $info .= "<id>" . $row['region_id'] . "</id>"; $info .= "<name>" . $row['region_name'] . "</name>"; $info .= "</res>";} $info .= "</mes>"; echo $info; ?>
3. Database function
function.php <?php function getresultById($id) { $con = mysql_connect("localhost","root",""); if($con) { $charset = "gb2312"; mysql_query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary"); //这句是必须的,解决中文乱码加密问题s mysql_select_db("ajax",$con); $sql = "select * from ecs_region where parent_id = '$id'"; $res = mysql_query($sql); $arr = array(); while($row = mysql_fetch_assoc($res)) { $arr[] = $row; } return $arr; } return false; }
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
ajax realizes the effect of changing the input box text and displaying the drop-down list
Automatically through JS code in Ajax Get form element value
#
The above is the detailed content of AJAX uses post to send data in xml format and receive data. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Use PHPXML functions to process XML data: Parse XML data: simplexml_load_file() and simplexml_load_string() load XML files or strings. Access XML data: Use the properties and methods of the SimpleXML object to obtain element names, attribute values, and subelements. Modify XML data: add new elements and attributes using the addChild() and addAttribute() methods. Serialized XML data: The asXML() method converts a SimpleXML object into an XML string. Practical example: parse product feed XML, extract product information, transform and store it into a database.

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

PHP is a programming language widely used in website development, and page jumps and carrying POST data are common requirements in website development. This article will introduce how to implement PHP page jump and carry POST data, including specific code examples. In PHP, page jumps are generally implemented through the header function. If you need to carry POST data during the jump process, you can do it through the following steps: First, create a page containing a form, where the user fills in the information and clicks the submit button. Acti in the form

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.

Title: PHP code example: How to use POST to pass parameters and implement page jumps In web development, it often involves the need to pass parameters through POST and process them on the server side to implement page jumps. PHP, as a popular server-side scripting language, provides a wealth of functions and syntax to achieve this purpose. The following will introduce how to use PHP to implement this function through a practical example. First, we need to prepare two pages, one to receive POST requests and process parameters
