【问题标题】:PUT on ajax instead of curlPUT 上 ajax 而不是 curl
【发布时间】:2018-02-01 20:37:47
【问题描述】:

我有这个 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");
                        }
                    },

【问题讨论】:

    标签: ajax api curl couchdb put


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 2021-02-28
      • 1970-01-01
      • 2014-03-14
      • 2021-08-03
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      相关资源
      最近更新 更多