使用angular js客户端对Python服务器进行rest调用的例子
Example on Making rest call to Python server using angular js client
谁能给一个例子,在使用Angularjs从/到python服务器获取和发布数据使用rest。请提供一个客户端(angularjs)和服务器(python)的例子。我的示例客户端代码是
var student_id = 12
$http({
method:"POST" // or get
url: //url to the python file
data: //this is what confusing me .. how to send that student id
}).success(function(data){
console.log(data);
})
在python中,我想运行一个函数打印student id
def print_info(id): ## here id is the student id that shall be recieved
print "student id is %s" %id
这里我希望js客户端发送该student_id值到python服务器,它应该接收它,并将print_info函数的值发送到客户端。
你可以这样使用:
$http.post('<your_url>', data).success(function(data) {
//handle the data returned
}, function(error) {
//handle if an error is thrown
})
你的数据格式可以是json,像这样:
data = {
"student_id": value
}
相关文章:
- 使用angularjs中的rest调用通过id获取数据
- 为什么使用AWS Signature v4对S3的REST调用并没有真正使用签名过程
- 如何通过脚本标记加载REST调用
- REST调用总是返回未定义的(Node.JS)
- AJAX rest调用错误”;意外的令牌<&”;
- Angular.js的多个rest调用范围问题
- 没有来自rest调用的数据
- 使用 feathersjs 通过简单的 rest 调用进行身份验证
- 如何使用 Javascript 对 SharePoint REST 调用进行身份验证
- 如何决定和进行与父子关系对应的 REST 调用
- JQuery REST 调用不起作用
- 第一个角度$http POST 落入 .then 错误路径,即使 REST 调用成功
- Azure Table Storage 通过 javascript 对 REST 调用进行身份验证
- 基本的REST调用WordPress V2 API与Angular.js
- 在 javascript 中保护 Azure API rest 调用
- 将异步 REST 调用 JSON 添加到 Angular $scope
- REST调用登录过程,我们如何处理重定向
- 仅对视口中的元素启用Ajax Rest调用
- AngularJS REST调用错误
- Phonegap没有执行ajax脚本(对后端的REST调用)