我是个新手,用Jquery编写了一段代码,在浏览器上向用户显示python程序的输出:
Project$(document).ready(function(){
$('#runReport').click(function() {
runreport($('#starttime').val(), $('#endtime').val());
});
function runreport(startdate, enddate) {
$('.date').html('');
alert ('this is a test ' + startdate + ' enddate ' + enddate);
$.ajax({
type: "GET",
url: "http://xx.xx.xx.xx/~prakash_prasad/project/runreport.py",
data: {
'startTime': startdate,
'endTime': enddate
},
success: function(result) {
alert ('Success' );
$("p").html(result);
},
error:function(xhr,err) {
alert("Failed\nreadyState: "+xhr.readyState+"\nstatus: "+xhr.status + "\nresponseText: "+xhr.responseText);
}
});
}
});
$(document).ready(function(){
$('.date').datepicker({
flat: true,
date: '2012-03-10',
current: '2012-03-10',
calendars: 1,
starts: 1
});
});
Start Date :
End Date :
Run Report
当我在浏览器中加载此html代码时,我按顺序收到以下警告消息:
第一条警报消息:
^{pr2}$
第二条警报消息:Failed
readyState: 0
status: 0
responseText:
在运行报告.py代码是:#!/usr/local/bin/python
import cgi
import MySQLdb
from xml.dom.minidom import Document
import json
print 'Content-Type: text/html\n'
print '
'form = cgi.FieldStorage()
starttime = form["startTime"].value
endtime = form["endTime"].value
print '%s' % (starttime)
print '%s' % (endtime)
print ''
我运行了我的python代码,它运行得很好。在project>$ curl "http://xx.xx.xx.xx/~prakash_prasad/project/runreport.py?startTime=2011-03-09&endTime=2012-03-07"
2011-03-09
2012-03-07
为什么我不能实现将python脚本的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文件是相同的?在