﻿//Ajax algemene functie om info op te halen uit webservice
function SendAjax(urlMethod, jsonData, returnFunction) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: urlMethod,
        data: jsonData,
        dataType: "json",
        success: function (msg) {
            // Do something interesting here.
            if (msg != null) {
                returnFunction(msg);
            }
        },
        error: function (xhr, status, error) {
            // Boil the ASP.NET AJAX error down to JSON.
            var err = eval("(" + xhr.responseText + ")");

            // Display the specific error raised by the server
            alert(err.Message);
        }
    });
}

function SendAjaxPicture(urlMethod, jsonData, returnFunction) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: urlMethod,
        data: jsonData,
        dataType: "json",
        dataFilter: function (data) {
        // This boils the response string down 
        //  into a proper JavaScript Object().
        var msg = eval('(' + data + ')');
        // If the response has a ".d" top-level property,
        //  return what's below that instead.
        if (msg.hasOwnProperty('d'))
            return msg.d;
        else
            return msg;
         },
        success: function (msg) {
            // Do something interesting here.
            if (msg != null) {
                returnFunction(msg);
            }
        },
        error: function (xhr, status, error) {
            // Boil the ASP.NET AJAX error down to JSON.
            var err = eval("(" + xhr.responseText + ")");

            // Display the specific error raised by the server
            alert(err.Message);
        }
    });
}



