Because the too much timeout errors in my requests I'd like to get the ajax answer's size in kilobytes. How can i do this? Thanks for the help.
The req开发者_Go百科uest is this:
$.ajax({
url: domain+'index.php?fx_action=ajax&fx_mode=aaa&fx_id='+id,
type: 'POST',
dataType: 'json',
timeout: 5000,
beforeSend: function () {
var currentTime = new Date()
window.time2b = currentTime.getTime();
},
error: function (xhr, ajaxOptions, thrownError) {
showErrorContainer();
appendError("function fname(params) : "+thrownError+", "+xhr.responseText);
return false;
},
success: function (data) {
It'll be in the response header.
var request = $.ajax(
...
success:function(msg){
var hdr =request.getAllResponseHeaders();
//parse the hdr and get the content - length
});
It seems like you are trying to do something similar to this: Ajax HEAD request via Javascript/jQuery
Basically, you need to do a head request and then check content-length.
If you are sending very high chunk of data from server, its generally not recommended. You can optimize your code, to send the json data over ajax and form htlm on client side.
It will have lots of data transfer.
精彩评论