简体   繁体   中英

How do I debug returned AJAX data in the console?

I have a function that makes an AJAX request and returns some data:

$(document).ready(function(){
    $("select#test").change(function(){
        $.ajax({
                url: "",
                data: { "value": $("#test").val(),
                csrfmiddlewaretoken: '{{ csrf_token }}'},
                dataType:"json",
                success: function(data){
                   $("div#return").text(data)
                }
            });
    });
});

When this is displayed it's displayed as [object Object] . I'd like to access it in the console but when I load the console and type data it tells me Uncaught ReferenceError: data is not defined(...)

The data is returned from my Django view and data is a JSON object as so:

    payload = {
        'main': {
            "title": "Jim",
            "description": "I am cool"
        }
    }

    return JsonResponse(payload, content_type='application/json')
success: function(data){
    console.log(data);
}

I'd just add a break point:

success: function(data){
  debugger;
}

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