Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quiz Question: How do I use webMethod to call GetMessages?
[WebMethod(true)]
public string GetMessages(string psUserId)
{
List<JxMessage> messages = new List<JxMessage>();
// .... do some logic like get the message list
// Send it back as JSON
return CxJSONHelper.Serialize(messages);
}
// Namespaces
if (typeof FrozenBytesCore == "undefined" || !FrozenBytesCore) {
window.FrozenBytesCore = { name: 'Frozen Bytes Core', version: '0.1.0.0' };
};
if (typeof FrozenBytesCore.Common == "undefined" || !FrozenBytesCore.Common) {
FrozenBytesCore.Common = { name: 'Frozen Bytes Core Common', version: '0.1.0.0' };
};
(function($) {
FrozenBytesCore.Common.JQueryHelper = {
// Make a JQuery.ajax call to a web method defined in options.url
//
webMethod: function(customOptions) {
var defaultOptions = { type: 'POST', async: true, cache: true, timeout: 1000, url: '../Services/CxJsonHandler.ashx', data: {} };
var options = $.extend({}, defaultOptions, customOptions);
var request = $.ajax({
type: options.type,
async: options.async,
cache: options.cache,
timeout: options.timeout,
url: options.url,
data: options.data,
contentType: "application/json; charset=utf-8",
dataType: "json"
});
request.fail(function(jqXHR, msg) {
var err = $.parseJSON(jqXHR.responseText);
alert("Error: " + err.Message);
});
return request;
},
} // End FrozenBytesCore.Common.JQueryHelper namespace
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment