簡體   English   中英

使用angular js client對Python服務器進行休息調用的示例

[英]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中我想運行一個打印學生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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM