jqueryajax和render oupu

2024-06-16 12:51:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个初学者,编写了一段代码来执行和转储通过AJAX调用生成的Python脚本中的数据:

<!DOCTYPE html>
<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>Project</title>
                <link type="text/css" href="jquery/css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
                <script type="text/javascript" src="jquery/js/jquery-1.7.1.min.js"></script>
                <script type="text/javascript" src="jquery/js/jquery-ui-1.8.18.custom.min.js"></script>
                <script type="text/javascript">
                        $(document).ready(function(){
                                $('.date').datepicker({
                                                        flat: true,
                                                        date: '2012-03-10',
                                                        current: '2012-03-10',
                                                        calendars: 1,
                                                        starts: 1
                                                     });
                        });
                        function RunReport() {
                                        $.ajax({
                                                type: "POST",
                                                url:  "http://xx.xx.xx.xx/~prakash_prasad/project/runreport.py",
                                                data:
                                                {
                                                                'startTime':$('#starttime').val(),
                                                                'endTime':$('#endtime').val()
                                                }
                                                success: function(html)
                                                {
                                                }
                                        });
                        }
                </script>
        </head>
        <body>
                Start Date : <input type="text" name="startdate" id="startdate" class="date"/>
                End   Date : <input type="text" name="enddate" id="enddate" class="date"/>
                <input type="button" value="Run Report" onClick="RunReport();"/>
        </body>
</html>

在运行报告.py代码是:

^{pr2}$

但是AJAX调用不起作用——我希望从Python脚本返回一个值并将其转储到浏览器中。在

另外,我想把开始/结束时间放在一些装饰的时间里,比如:

 Start Date [           ]                         End Date [           ]
                                [] Run Report

脚本/html页面位于同一域中:

project>$ curl "http://xx.xx.xx.xx/~prakash_prasad/project/runreport.py?startTime=2011-03-09&endTime=2012-03-07"
<html><body>
<b>2011-03-09</b>
<b>2012-03-07</b>
</body></html>

请指教

==========================================================================================

我下载了Firebug,下面是我在Net标签中看到的日志:

Headers
Response Headersview source
Connection  Keep-Alive
Content-Type    text/plain
Date    Sun, 11 Mar 2012 17:08:45 GMT
Keep-Alive  timeout=5, max=100
Server  Apache/2.2.17 (Unix) PHP/5.3.3 mod_wsgi/3.3 Python/2.7.1 mod_jk/1.2.31 mod_perl/2.0.5 Perl/v5.8.8
Transfer-Encoding   chunked



Request Headersview source
Accept  */*
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Host    xx.xx.xx.xx
Origin  http://tools
Referer http://tools/~prakash_prasad/project/p.html
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2


http://xx.xx.xx.xx/~prakash_prasad/project/runreport.py?startTime=03%2F09%2F2012&endTime=03%2F23%2F2012     Size 64B Status 200 OK Domain same host where my HTML file is there

请告知。在

==========================================================================================

!!!!!解决了的!!!!!在

问题是我错误地使用了AJAX URL结构:

url:  "http://xx.xx.xx.xx/~prakash_prasad/project/runreport.py",

当我把它改成:

url:  "runreport.py",

它工作得很好

请告知通过Jquery通过上面两个ajaxurl调用有什么区别-尽管doamin对于python脚本和html文件是相同的?在


Tags: textpyproject脚本httpdatehtmltype