Skip to content Skip to sidebar Skip to footer

Using One Ajax Call With Json, Or Two Ajax Calls With Html?

I have an element that contain many messages. each message is an HTML element

Solution 1:

Don't bother about client performance if not necessary. Make one AJAX call and sort things out with client-side JS. Remember that your server has to process lots of requests but the web browser has to deal with only a couple of requests. So if you can always put the job on the client-side - he/she won't notice but they'll definitely notice if your server is constantly bombarded with lots of incoming requests. Grab JSON and let JS do the job.

Solution 2:

I'd keep it one Ajax call. Json is probably the best for that, as you mentioned. Alternatively and depending on your structure, PHP can return pure HTML, and JavaScript/jQuery can then put it in place using the innerHTML method.

Post a Comment for "Using One Ajax Call With Json, Or Two Ajax Calls With Html?"