简体   繁体   中英

how to display the json data from browser response header

Actually i should display the JSON data in a browser, so far i am getting the data in browser response body but here is the problem. i am facing that not able to display it in browser here picture for better understanding, any one please help me. Thanks in advance.

HTML code is:

<!DOCTYPE html>
<html lang="en">
<head><title>Demo</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /></head>

<body>
  <input id="testbutton" type="button" value="Test" />
  <p id="results">results appended here: </p>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("#testbutton").click(function() {
        $.ajax({
            url: 'http://localhost:8080/SMWS/Rest/parentService/parent/getSchoolDetails',
            dataType: 'jsonp',
            success: function(data) {
                $("#results").append('all good');
                alert(JSON.stringify(data));
            },
             error: function() {
                $("#results").append("error");
                alert('error');
            }
        });
    });
});
</script>
</body>
</html>

这是要理解的形象

  1. There are plenty of questions about ajax requests that have response status 200 but raise errors. Take a look at this one for example. In this thread it is suggested that error might be caused by the malformed json the server is sending to you. You can check out Corvin's answer and jaketrent's answer .
  2. In order to find out the error response message you may look at this thread . Define this as your error handler and look for the responseText property of xhr parameter:

     error: function(xhr, status, error) { console.log(xhr.responseText); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM