Reputation: 127
I'm fairly new to working with client-side coding and was wondering what the the best way of returning a single ID from a simple Insert in a web service would be.
Copying code that returns more complex JSON objects, I'm doing the following:
Dim JaggedArray As String()() = New String(0)() {}
Dim i As Integer = 0
JaggedArray(i) = New String() {<insert stmt, returns integer>}
Dim js As New JavaScriptSerializer()
Dim strJSON As String = js.Serialize(JaggedArray)
Return strJSON
I then use the following to access the ID in Javascript (excerpt from the AJAX call):
success: function(data) {
var c = eval(data.d);
var testID = c[0][0];
Surely there's a less clunky way of doing this, right?
And this is a stupid question, but can (and / or should) you put code outside of the Success callback, or is this mandatory?
Upvotes: 0
Views: 94
Reputation: 133403
Surely you can use jqXHR.done An alternative construct to the success callback option, the .done(),
for more info visit http://api.jquery.com/jQuery.ajax/
$.ajax({
//ajax stuff ..
})
.done(function(return){
var output = "hello";
return output;
});
Upvotes: 1