How to return value from Python as JSON?

后端 未结 2 1605
梦如初夏
梦如初夏 2021-02-14 06:23

I sending ajax request from a jQuery file like below, which expects response in JSON.

jQuery.ajax({
    url: \'/Control/getImageDetails?file_id=\'+currentId,
            


        
2条回答
  •  借酒劲吻你
    2021-02-14 07:12

    return json.dumps(return_info)

    main problem is

    return_info = [record.file_id, record.filename, record.links_to]
    

    because JSON format is generally like

    Example:

    json.dumps({'file_id': record.file_id, 'filename': record.filename , 'links_to' : record.links_to})
    

    and the message you are going to receive is [object Object] if you use alert(data)

    So use alert(data.file_id); if you use the example

提交回复
热议问题