What is ajax?
The ajax() method loads remote data through HTTP requests.
This method is the underlying AJAX implementation of jQuery. For simple and easy-to-use high-level implementations, see $.get, $.post, etc. $.ajax() returns the XMLHttpRequest object it created. In most cases you won't need to manipulate this function directly unless you need to manipulate less commonly used options for more flexibility.
In the simplest case, $.ajax() can be used directly without any parameters.
#Where are the results obtained from the ajax request?
success: The parameter is required to be Function type. The callback function called after the request is successful has two parameters.
(1) Data returned by the server and processed according to the dataType parameter.
(2) Describe the string of the state.
FUNCTION (Data, TextStatus) {
// Data may be XMLDOC, JSONOBJ, HTML, Text, etc.
#How to display the returned results?
Here is an example, page js code:
<script> //ajax页面刷新 function changeDept() { //var areaID = document.getElementById("areaId").value; //var types = 'PERSONAL'; $.ajax({ type : "post", dataType : "json", //url : "${path}/businessguide/findOrgByDivisionCode.action?divisionCode="+ areaID, success : function(data) { //方法一: var status = data.status; if (data.code == "0") { $(".weather").empty(); $(".weather").text("温度" + data.temp + "天气" + data.weather + "图标"+ data.weatherimg); } else { alert(data.status); } //方法二: var html=''; var status = data.status; if (data.code == "0") { $(".weather").empty(); html+='"温度" + data.temp + "天气" + data.weather + "图标"+ data.weatherimg'; $(".weather").append(html); } else { alert(data.status); } } }); } </script>
Page calling code:
<body> <span class="weather"> </span> </body>
The above is the detailed content of How to display data in ajax. For more information, please follow other related articles on the PHP Chinese website!