2017-06-01 33 views
0

我正在應用程序的前端工作。我需要從html模板發送刪除請求到服務器。刪除功能的工作原理如下:如何發送刪除請求到python服務器

def do_DELETE(self): 
     if re.match(r'\/product\/\d+', self.path): # match "/product/{ID}" 
      #send response code: 
      self.send_response(200) 
      #send headers: 
      self.send_header("Content-type:", "application/json") 
      # send a blank line to end headers: 
      self.wfile.write("\n") 
      #send response: 
      db.delete(re.search(r'[^/]*$', self.path).group(0)), self.wfile 
      return 

我明白URL請求會,說,/product/2。不過,我更熟悉節點的風格,例如:

<form id="delete-form" action="product/<%= product._id %>?_method=DELETE" method="POST"> 
    <input type="submit" value="Delete"> 
</form> 

我無法找到他們的方式在發送請求到服務器蟒蛇時,這將被處理。

我該如何發送一個url到python服務器中的刪除請求?

回答

0

您需要向服務器發送HTTP DELETE請求。您正在發出POST請求,並且您有一個DELETE處理程序。

您應該使用JavaScript來創建DELETE請求。

function reqListener() { 
    console.log(this.responseText); 
} 

var oReq = new XMLHttpRequest(); 
oReq.addEventListener("load", reqListener); 
oReq.open("DELETE", "/product/2"); 
oReq.send(); 
相關問題