【问题标题】:Http PUT to a JSON storeHttp PUT 到 JSON 存储
【发布时间】:2013-08-24 07:35:58
【问题描述】:

以下 JavaScript 代码 sn-p 的 LiveCode 等效项是什么?

            var req = new XMLHttpRequest();
            req.open("PUT", theURLoftheNoSQLstore, false);  
            req.setRequestHeader('Content-Type', mimeType);
            req.send(theJSONobjString); 

参数已定义为

            theJSONobj   = {};
            theJSONobj["aKey"] = "aValue";
            theJSONobj["anotherKey"] = 123;
            theJSONobj["note"] = "some note about the issue";
            theJSONobjString = JSON.stringify(theJSONobj);
            theURLoftheNoSQLstore ="http://localhost:5984/thedb/thekey"

            mimeType="application/json";

注意

已添加设置 mimeType 以确保完整性。但是,对于发布到 JSON 存储,它不是必需的,因为在这种情况下这是默认设置(couchDB)。

参考文献

mime type
XMLHttpRequest

【问题讨论】:

    标签: json http couchdb put livecode


    【解决方案1】:

    您的 JavaScript 的 LiveCode 等效项应该是:

    set the httpHeaders to "Content-Type: application/json"
    put "[" into myJson
    // add one record
    put "{'key1':'data1','key2':'data2'}" after myJson
    // don't forget commas between multiple records
    put "]" after myJson
    // next line may not work with more complex data
    replace "'" with quote in myJson
    // server must be able to process PUT
    put myJson into URL "http://localhost:5984/thedb/thekey"
    put the result into rslt
    if rslt is not empty then
      beep
      answer error rslt
    end if
    

    【讨论】:

    • 在你发送 JSON 对象而不是 JSON 数组的情况下可以很好地与 couchdb 配合使用。所以只有 {"key1":"data1","key2":"data2"} 而不是 [{"key1":"data1","key2":"data2"}]
    • 我认为 Hannes 没有在任何地方提到移动,还是我忽略了它?
    • 不,你不知道这只是一个以防万一的便条
    • 到目前为止,我已经在带有 LiveCode 6.0 的 Ubuntu 12.04 (LTS) 上对其进行了测试。 More 在使用的​​数据库上...
    猜你喜欢
    • 2019-05-08
    • 2019-05-06
    • 2017-08-03
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多