What i would normally do is generate the html in the webservice then display it on jquery... i bet there's a better way. help!
+1
A:
return json object in your webservice and render the div's in jquery and you may use this chain.js
rob waminal
2010-08-06 10:55:34
will the client machine's performance factor in your suggestion?
Martin Ongtangco
2010-08-09 02:54:19
since you are already using jQuery, client machine's performance is already a factor. if you are returning a json object, the performance from your server will be much faster than it is creating the DOM element from the server. The faster, you come back from your server, the lesser the client waits for a reply. And rendering the DOM jQuery is not a very big factor in performance.
rob waminal
2010-08-09 03:04:10
so maybe it's safe to say that I should monitor performance between rendering via serverside or clientside. maybe what I'm really asking is for the silver bullet, which doesn't exist. thanks, i'm enlightened now.
Martin Ongtangco
2010-08-09 03:08:48
A:
If you think about it, you'll always come to two conclusions:
"pre render" HTML serverside and send the whole package to a browser
= more traffic over the wire, faster rendering, less client cpu usage
sending only data & instructions (eg. JSON)
= less traffic over the wire, more client cpu usage, possibly slower rendering
So it actually it depends on your needs. How many people are going to access your data, etc.
jAndy
2010-08-06 11:00:56
i assume the same jAndy, if you were to do this, what are the conditions you take when considering the factors? thanks!
Martin Ongtangco
2010-08-09 02:53:42
A:
Here is a typical jQuery AJAX call to a webservice to get div data and how to handle it.
Assumptions:
- You are passing a divId to the service to get a particular div. You can change the parameters sent in the data variable to meet your own needs, as long as they match the parameters of the WebMethod.
You know where you want to put the result: targetLocation
$ajax({ type: "POST", url: "WebServices/YourService.asmx/GetDivs", data: "{'divToGetId' :'" + divId + "'}", dataType: "json", contentType: 'application/json; charset=utf-8', success: function(json) { var result = eval("(" + json.d + ")"); $(targetLocation).html(result.value); } });
Your webservice:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod(EnableSession = true)]
public string GetDivs(string divId)
{
return DivProvider.GetChildDivs(divId);
}
Your json should be returned as something like:
{"value": "<div>contents of div 1</div><div>contents of div 2</div>"}
Daniel Dyson
2010-08-06 12:01:26
thanks for the suggestion, but my question is the other way around.
Martin Ongtangco
2010-08-09 02:52:53