locked
javascript JSON POST multiple entries RRS feed

  • Question

  • I am using WCF Data Services to expose my data to a jQuery JSON ajax call and then displaying in a table. The retrieve is really easy - I just pass the correct url to the WCF Data Service and it returns the JSON to fill my table.

    However, I am having issues with the Save/POST. I can post a single entry easily like this:

    var postParams = {};
    postParams["ID"] = id;
    postParams["Value"] = value;
    
    $.ajax({
    type: "POST",
    url: "/service.svc/item(\'" + id + "\')/Values",
    data: JSON.stringify(postParams),
    contentType: "application/json; charset=utf-8",
    });

    My issue is - how do I pass "multiple" items to a WCF Data Service using JSON?

    Thanks,

    Greg

    p.s.

    It's really hard to search for these types of answers because Microsoft changed the name from ADO.Net Data Services to WCF Data Services. Every search focuses on the Word WCF and talks about custom Web Services. I love the idea of REST, but I am struggling with the documentation to save data.

    Friday, September 7, 2012 3:12 PM

Answers

  • Hi,

    It depends on what you mean to "pass" multiple items. If you're trying to add multiple entities into an entity set, just send several POST requests. Similar for updates and so on. If you have many of these it might be better to send a batch request. http://www.odata.org/documentation/batch

    All of this is made much easier if you use the javascript library for OData consumption. datajs : http://datajs.codeplex.com/

    Thanks,


    Vitek Karas [MSFT]

    Friday, September 7, 2012 5:29 PM
    Moderator