Home  >  Article  >  How to display data in ajax

How to display data in ajax

anonymity
anonymityOriginal
2019-05-08 11:44:253000browse

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.

How to display data in ajax

#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 data in ajax#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 = &#39;PERSONAL&#39;;
        $.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=&#39;&#39;;
                var status = data.status;
                if (data.code == "0") {
                    $(".weather").empty();
                    html+=&#39;"温度" + data.temp + "天气" + data.weather + "图标"+ data.weatherimg&#39;;
                    $(".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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to solve 414requestNext article:How to solve 414request