2017-08-24 91 views
0

我有這個捲曲URL連接到couchDB。上ajax而不是捲曲

捲曲-X PUT http://admin:[email protected]:5984/test/ 「001」 -d '{ 「名」: 「莫伊塞斯」}'

我看到了很多與GET和POST問題,但我沒有找到與PUT的例子。

我這樣做是正確的嗎?

$.ajax({ 
        crossOrigin: true, 
        url : 'http://admin:[email protected]:5984/test/'+user, 
        type : 'POST', 
        processData: false, 
        dataType: 'json', 
        contentType: 'application/json', 
        data: {pass:pass,email:email}, 
        success:function(result){ 
         if(result!="error"){ 
          alert("Registro Correcto, Proceda a entrar"); 
          open("login.html","_parent"); 
         }else{ 
          alert("Usuario Ya Utilizado"); 
         } 
        }, 

回答

0

PUT HTTP動詞被用來或者:

  • 例如創建一個數據庫curl -X PUT http://localhost:5984/mydb
  • 當您知道要創建的文檔的ID時,在數據庫中創建文檔,例如,

# create a document with PUT with document id in the URL 
curl -X PUT -d '{"a":1,"b":2}' -H 'Content-type: application/json' http://localhost:5984/mydb/mydocid 
{"ok":true,"id":"mydocid","rev":"1-25f9b97d75a648d1fcd23f0a73d2776e"} 

這是等價的:

# create a document with POST with the document id in the body 
curl -X POST -d '{"_id":"mydocid","a":1,"b":2}' -H 'Content-type: application/json' http://localhost:5984/mydb/mydocid