0

AJAX 経由でバックエンドの Python プログラムを呼び出す Web ページがあります。

function runreport(datastring)
{
        $.ajax({
                type: "POST",
                url:  "runprogram.py",
                data:
                {
                        'form_data' : datastring
                },
                success: function(json)
                {
                        $("div#report_result").show();
                        alert($(json));
                        var oTable = $('#example').dataTable($(json));
                        $('html, body').animate({scrollTop:$(document).height()}, 'slow');
                },
                error:function(xhr,err)
                {
                     alert("Failed\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status + "\nresponseText: "+xhr.responseText);
                }
         });
}

私の要件は、DataTables のデータセットを生成し、UI でレンダリングすることです。バックエンド スクリプトは、静的なデータ セットを返します。

#!/usr/local/bin/python

import cgi
import MySQLdb
import json

print "Content-Type: application/json"
print

displaylength = 5
output = "{\n"
output += '"iDisplayLength":' + str(displaylength) + ',\n'
output += '"sPaginationType": "full_numbers",\n'
output += '"bProcessing": true,\n'
output += '"bDestroy": true,\n'
#output += '{\n'
output += '"aaData": [\n'
output += '{\n'
output += '"First Field": "First Field Value",\n'
output += '"Second Field": "Second Field Value",\n'
output += '"Third Field": "Third Field Value",\n'
output += '"Fourth Field": "Fourth Field Value",\n'
output += '"Fifth Field": "Fifth Field Value",\n'
output += '"Sixth Field": "Sixth Field Value",\n'
output += '"Seventh Field": "Seventh Field Value",\n'
output += '"Eight Field": "Eight Field Value",\n'
output += '"Nineth Field": "Nineth Field Value"\n'
output += '},\n'
output += '{\n'
output += '"First Field": "First Field Value",\n'
output += '"Second Field": "Second Field Value",\n'
output += '"Third Field": "Third Field Value",\n'
output += '"Fourth Field": "Fourth Field Value",\n'
output += '"Fifth Field": "Fifth Field Value",\n'
output += '"Sixth Field": "Sixth Field Value",\n'
output += '"Seventh Field": "Seventh Field Value",\n'
output += '"Eight Field": "Eight Field Value",\n'
output += '"Nineth Field": "Nineth Field Value"\n'
output += '}\n'
output += ']\n'
#output += '}\n'
output += '"aoColumns": [\n'
output += '{ "sTitle":"First Field", "mDataProp": "First Field" },\n'
output += '{ "sTitle":"Second Field", "mDataProp": "Second Field" },\n'
output += '{ "sTitle":"Third Field", "mDataProp": "Third Field" },\n'
output += '{ "sTitle":"Fourth Field", "mDataProp": "Fourth Field" },\n'
output += '{ "sTitle":"Fifth Field" , "mDataProp": "Fifth Field" },\n'
output += '{ "sTitle":"Sixth Field", "mDataProp": "Sixth Field" },\n'
output += '{ "sTitle":"Seventh Field", "mDataProp": Seventh Field" },\n'
output += '{ "sTitle":"Eight Field", "mDataProp": "Eight Field" },\n'
output += '{ "sTitle":"Nineth Field", "mDataProp": "Nineth Field" }\n'
output += ']\n'
output += '}\n'
print output

しかし、UI 側で目的の出力を取得できません。UI/バックエンドの実装は正しいですか?

4

0 に答える 0