0

Hi i want make a Json for my POST with a array who contain all my modifications like :

    var tabname = ["test 1", "Test 2", "Test 3"];
    var tabID = [1, 2, 3];

    to build at the end a json like that : 

    ----------------- HOW MAKE THAT ??---------------------
    - var item = {
    -     "__metadata": { "type": itemType },
    -     "test 1" : 1 //tabname[i]: tabID[i]
    -     "test 2" : 2 //tabname[i]: tabID[i]
    -     "test 3" : 3 //tabname[i]: tabID[i]
    - };
    ------------------HOW MAKE THAT ??---------------------



    var data  = JSON.stringify(item);


$.ajax({
        url: URL,
        type: "POST",
            data: data,
            contentType: "application/json;odata=verbose",
            headers: {
                "Accept": "application/json;odata=verbose",                
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "X-HTTP-Method": "MERGE",
                "If-Match": "*"
            },
            success: function (data) {
                console.log(data);
            },
            error: function (data) {
                console.log(data);
            }
    });

Thanx !

0
var item = { "__metadata" : { "type" : itemType } };

for (var i = 0; i < tabname.length; i++) {
    item[tabname[i]] = tabID[i];
}

var data = JSON.stringify(item);
  • it works !!! thx – Nuno Feb 13 '17 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.