Javascript未执行Ajax调用



我有一个在localhost上运行的HTML页面。我想从Python脚本中访问一些数据,并在我的HTML页面中使用它,函数中的Ajax调用不起作用,如果我删除它,程序将完美运行。有什么帮助吗?

Javascript函数:

<script src="/js/jquery.min.js" type = "text/javascript" ></script> 
     <link rel="stylesheet" href="LoginStyle.css" type="text/css" />
 <script type = "text/javascript" >
function getData()
{
//Code doesn't even enter this function but when i remove the $.ajax part it enters the function
alert("I AM HERE");
$.ajax(
{
type: "GET",
url: "/cgi-bin/check.py" // Path of the script/code i want to run
success: function(response)
{
    $("#username").text(data); //this is where i should get the response, Not sure about the syntax i.e. whether i should 
//output in a <div> tag or a text box
}
});
}

调用HTML中的函数如下:

<form name="login-form" class="login-form" action="" method="post" onsubmit="getData();return false;"">
<input id="Uname" name="username" type="text" class="input username" placeholder="Username" />

Python脚本:

#!/usr/bin/python
from StringIO import StringIO
import json
def htmlData():
    content=json.loads('{"access": {"token": {"issued_at": "2013-04-18T14:40:23.299903", "expires": "2013-04-19T14:40:23Z", "id": "4c5ef01f52c7404fb5324c520d25d1fe"}}}')
data=json.dumps(content, indent=4, separators = (', ', ': '))
    print data
    return
htmlData()

url属性中缺少,

function getData() {
    //Code does not even enter this function but when i remove the $.ajax part it enters the function
    alert("I AM HERE");
    $.ajax({
        type: "GET",
        //--> here missing , in url
        url: "/cgi-bin/check.py", // Path of the script/code i want to run
        success: function (response) {
            $("#username").text(data); //this is where i should get the response, Not sure about the syntax i.e. whether i should 
            //output in a <div> tag or a text box
        }
    });
}

尝试使用,您错过了添加url字符串的,结尾

url: "/cgi-bin/check.py",

而不是

 url: "/cgi-bin/check.py"

相关内容

  • 没有找到相关文章

最新更新