PUT on ajax而不是curl

时间:2017-08-24 05:25:28

标签: ajax api curl couchdb put

我有这个curl URL连接到couchDB。

curl -X PUT http://admin:ulacit@13.90.93.32:5984/test/“001”-d'{“name”:“moises”}'

我看到很多关于GET和POST的问题,但我没有找到PUT的例子。

我这样做是正确的吗?

$.ajax({
                    crossOrigin: true,
                    url : 'http://admin:ulacit@13.90.93.32: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");
                        }
                    },

1 个答案:

答案 0 :(得分: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