0

以下 JavaScript 代码片段的 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)。

参考

哑剧类型
XMLHttpRequest

4

1 回答 1

2

您的 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
于 2013-08-24T11:01:04.597 回答