2013-08-24 5 views
0

Что такое эквивалент LiveCode следующего фрагмента кода JavaScript?Http PUT в магазин JSON

  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

ответ

2

LiveCode эквивалент вашей JavaScript должен быть:

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 
+0

отлично работает с CouchDB в случае, если вы отправляете объект JSON, а не массив JSON , Таким образом, только {"key1": "data1", "key2": "data2"}, а не [{"key1": "data1", "key2": "data2"}] –

+0

Details ......;) – Mark

+1

Обратите внимание, что на данный момент нет мобильного телефона на мобильном телефоне –