willowsystems / jSignature

jQuery plugin - draw signature in browser.
720 stars 266 forks source link

jSignature + asp.net Best Practice? #22

Open jagilbert opened 11 years ago

jagilbert commented 11 years ago

Is there a "best" way to getData() from the client to the server in asp.net. I've seen references to using json or putting data in a hidden field. I'd like to use a tried and true method instead of reinventing it myself.

Cheers, Jeff

Gfweis commented 11 years ago

I use webservices. Something like...

// Accept Signature ///////////////////////////////////////////////////////////////////////////////// var baseUrl = RootUrl + "WebServices/Pt.asmx/";

function SignatureAccept() { var $cbs = $('input[name="ToDeliver"]'); // This is series of Checkboxes var Keys = ''; $cbs.each(function () { if (this.checked) Keys += this.value + "~"; }); var Signature = $("#divSignature").jSignature("getData", "base30"); var Notes = $('#deliveryNotes').val(); var Confirm = ($("#deliveryConfirmation").val() === '1'); var jsonData = JSON.stringify({ "Token": Token, "SignatureType": Signature[0], "SignatureData": Signature[1], "Keys": Keys, "Notes": Notes, "Confirm": Confirm }); $.ajax({ url: baseUrl + "DeliverE", data: jsonData, success: function (data) { if (data.d.Success) { // Variable passed back from webservice $("#divShowPackages").hide(); // hide a few items $("#divGetSignature").hide(); $("#divFindResident").show(); // screen that we want to show $("#divSignature").replaceWith(divCloneSignature); // Copy of the div before drawing signature Clear(); // Clears some of our variables var Keys = ''; SoundComplete(); // Beeps on success } MessagesShow(data.d.Message); // Our message handler } }); }

Hope this helps.