繁体   English   中英

为什么我的ajax电话无效?

[英]Why is my ajax call not working?

我有一个像控制模块一样工作的html页面,并且有一个按钮,当点击它时会运行一个触发警报的python脚本。 当我点击它时,它什么也没做。 然而,我没有在开发人员工具中遇到任何错误。 python代码工作,所以脚本不是问题,但我的ajax请求。

这是代码:

<input type='button' class="btn btn-default" value='Alarm ON' id = 'alarm'>

<script>
        $("#alarm").click(function()
        {
            $.ajax({
            type: "GET",
            url: "lib/scripts/AlarmON.py",
            success: function(response){}
            });
        })
</script>

我知道这个电话是否有效,因为我房间的闹钟会响起。

编辑:对于那些感兴趣的人,这是我的脚本:

import suds
from suds.client import Client
from suds.transport.http import HttpAuthenticated
from suds.sax.text import Raw

def main():
    #Sends a network message to device to trigger an alarm
    url = "http://foobar/WSDL/v4.0/iLON100.WSDL"
    client = Client(url, username='ilon', password='ilon', location = 'http://foobar/WSDL/iLON100.WSDL')
    xml = Raw('<Item><UCPTname>Net/MB485/PLC/Virtual Fb/y2</UCPTname><UCPTvalue>TRUE</UCPTvalue></Item>')
    client.service.Write(xml)

if __name__ == "__main__":
    main()

更新我把document.write(“hi”)放在success()中,如果调用有效,它会把hi写入页面,所以我不确定是怎么回事......

你不能直接执行python脚本。 看看这里: http//docs.python.org/2/howto/webservers.html

还包括函数错误,看看会发生什么:

<script>
    $("#alarm").click(function()
    {
      $.ajax({
        type: "GET",
        url: "lib/scripts/AlarmON.py",
        success: function(response){
            console.log(response);
        },
        error: function(xhr){
            var status = xhr.status;
            var text = xhr.statusText;
            console.log( status + ': ' + text);
        }
      });
    })
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM