jQuery AJAX Post方法错误(语法错误)

2024-06-26 14:03:40 发布

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

我有一个Linux机器上的网页,需要在我的JavaScript函数中运行Python脚本。 脚本位于服务器上,与html文件位于同一目录中,需要在服务器上运行,而不是在客户端上运行。在

我尝试使用以下方法:

$.ajax({
    type: "POST",
    url: "scripti.py",
    success: function(resultData) { alert("Success") },
    error: function(resultData) { alert("Error") }
});

我得到了这些错误(在开发人员工具上):

^{pr2}$

当然,这个脚本可以手动运行。在


Tags: 文件方法函数服务器目录脚本机器网页
2条回答

我认为IDE期望回调,可能应该包括success和error事件。在

您的浏览器无法执行python代码,它只运行Javascript,因此即使您下载了python文件,也不会执行它。您需要在服务器端运行它:(

您正在使用jQuery获取一个文件。默认情况下,jQuery需要xml、json、script或html格式的文件,因此您会收到语法错误

dataType (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are: ...

jQuery documetnation

您需要开发一个webservice来调用URL,jQuery和运行在服务器上的python应用程序(使用restapi返回JSON)$ 这里有一些工作要做,所以如果你从来没有在这样的基础设施上工作过,那就要花几天/几周的时间。在

相关问题 更多 >