Ajax Json parsed blank result

I am trying to parse some JSON data through AJAX i followed an example from here:

how to parse json data with jquery / javascript?

On the example, they can get it working, but on my exmaple, the

turned blank.

I tried just echoing the php, the JSON displayed with no problem either. Wondering what the problem is.

<!DOCTYPE HTML>
<html>
<head>
  <link type ="text/css" rel="stylesheet" href= "css/bootstrap.css">
 <link type ="text/css" rel="stylesheet" href= "css/account.css">
</head>



 <body>
    <p id="result">fefe</p>>
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="js/bootstrap.min.js"></script>
     <script>
    $.ajax({ 
                    type: 'GET', 
                    url: 'get.php', 
                    data: { get_param: 'value' }, 
                    dataType:'json',
                    success: function (data) { 
                                        var names = data
                        $('#result').html(data);
                    }
                });
        </script>
    </body>
    </html>

What the JSON result looks like in php:

    [{"id":"1","userid":"26","title":"654","description":"654"}]

Answers:

Answer

what is the type of data? try add this line in your code on success function

success: function (data) {
    console.log(data);
}

is it an array of objects, if yes maybe you can try this

$.ajax({ 
    type: 'GET', 
    url: 'get.php', 
    data: { get_param: 'value' }, 
    dataType:'json',
    success: function (data) { 
        for(var i=0; i<data.length; i++) {
            // do your things here using data[i].description until data[i].userid
        }
    }
});
Answer

Try this

$.ajax({
      type: "GET",
      dataType: "json",
      url: "getjobs.php",
      data: data,
      success: function(data) {
       $('#result').html(data);

        }
      });
Answer

Try setting $.ajax's datatype is set to jsonp. Also try to alert the return value.

      $.ajax({ 
            type: 'GET', 
            url: 'get.php', 
            data: { get_param: 'value' }, 
            dataType:'jsonp',
            success: function (data) { 
                alert('data is ::' +data);
                $('#result').html(data);
            }
        });
Answer

Try this:

$.ajax({ 
            type: 'GET', 
            url: 'get.php', 
            data: { get_param: 'value' }, 
            dataType:'json',
            success: function (data) { 
                 console.log(data);
            }
        });

in the console(such as chrome browser`s development tools), you can see the actual result.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.