Should ASP.NET AJAX be avoided in heavy pages? - performance

I'm getting some js errors only for some users, and only every once in a while on a page that uses quite a bit of ASP.NET AJAX.
The page also does some intense SQL querying and some string manipulation to highlight text found in the search results.
Could this be a result of performance? Is it always safe to use ASP.NET AJAX in demanding situations or should I be looking to other AJAX techniques?
(By the way the errors I sometime see are):
Message: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 12031
Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near ' '.

ASP.NET AJAX has been known to not be the most performance intensive approach, but that's what you got i suppose in exchange for how simple it is to implement.
I do know you aren't allowed to do any Response.Writes within an update panel. That will cause your second error.

This particular exception is very
common and can be caused by any one of
the following:
1. Calls to Response.Write():
By calling Response.Write() directly you are bypassing the normal
rendering mechanism of ASP.NET
controls. The bits you write are going
straight out to the client without
further processing (well, mostly...).
This means that UpdatePanel can't
encode the data in its special format.
2. Response filters:
Similar to Response.Write(), response filters can change the
rendering in such a way that the
UpdatePanel won't know.
3. HttpModules:
Again, the same deal as Response.Write() and response filters.
4. Server trace is enabled:
If I were going to implement trace again, I'd do it differently.
Trace is effectively written out using
Response.Write(), and as such messes
up the special format that we use for
UpdatePanel.
5. Calls to Server.Transfer():
Unfortunately, there's no way to detect that Server.Transfer() was
called. This means that UpdatePanel
can't do anything intelligent when
someone calls Server.Transfer(). The
response sent back to the client is
the HTML markup from the page to which
you transferred. Since its HTML and
not the special format, it can't be
parsed, and you get the error.
Complete Post : ASP.NET AJAX and Sys.Webforms.PageRequestManagerServerErrorException
You can grab the code which causes the error by using Visual Studio Debug feature. I don't know much but maybe it can help and also Firebug will help you to see server response and data you submit to the server.
Here is a video where you can see how to use Firebug to debug Ajax.
See how I used Firebug to learn jQuery
But I don't think Asp.NET Ajax should be avoided in heavy loaded pages. That is actually what Ajax stands for right ? I mean it also relieves servers to send small pieces of pages instead of requesting the whole page again.

Related

Why the HTTP Request return that the response is not in JSON format?

I built a flow that will generate an SSRS report as PDF dynamically from Dynamics by following this amazing article:
D365 Reports as PDF using Power Automate
After I have followed all the steps mentioned and performed different testing, sometimes the flow calls the API and output, as a result, the content type of the file, and sometimes it fails with the below response using the same report ID:
Inner Error returned:
""innerError": "<html><head><title>Object moved</title></head><body>\r\n<h2>Object moved to here.</h2>\r\n</body></html>\r\n"
Succeeded Run (Without any changes to the flow):
Actions scope screenshot:
-- Updated logic to handle HTTP request:
This flow really scares me as it might and might not work because I will be sending this report to our customers and I want to avoid any issue that might happen to the flow.
Kindly note that if you try to reproduce the same flow you will encounter the same issue.
Any idea what will be the workaround to handle this issue and to avoid flow failure?
Any help is highly appreciated.
I solve this issue adding "Accept: {asterik}/{asterisk}" to the Header. sometimes the request returns the redirect error in this case try to repeat the request making the same request again(using run after setting).
fix screen

jQuery ajaxcall - is there a better way to find the ajaxcaller..?

In my app, I am initiating 30 to 40 ajax calls on load. I got an issue with one of that ajax response..
But i unable to find the where that call is initiateda and called (response).. is there any way to stop the calls and find each of them with their caller details..
please bear with me, in case my question is meaning less.. still i am looking for some idea..
I just looking for the last caller of this screen shot.
As per my understanding, you're looking for fine way to debug the ajax. You can't debug the response but it is possible to check the what are the call made using Firebug or network tab in Google developer tools.
Using this you can easily find the call requested to server and remove the unwanted ajax calls.

How to debug a failed ajax request in google chrome?

I have a web application that crashes on ajax requests with google chrome (it works with every other web browser it was tested it). After debugging I found that the error is caused by response.responseText being undefined. The xhr object looks like this:
argument: undefined
isAbort: false
isTimeout: undefined
status: 0
statusText: "communication failure"
tId: 3
In debugger in the 'network' tab I get "(failed)", however all the headers are there and I can even copy into clipboard the response body (which is a valid JSON).
My question is - how can I debug this problem? Where to find additional information, what causes this request to fail?
I finally found the solution to my problem : AdBlocks, when it blocks an ajax request, it just says "communication failure".
The first thing I would double-check is that the data coming back from the response is valid JSON. Just pass it through a JSON validator like this online JSONLint: http://jsonlint.com/
I assume that you are using something like jQuery to make your AJAX requests. If so, then make sure that you are using the development version of that library. Now that you are using the development version (uncompressed) of the script, find the particular function that you are using (eg. $.ajax) and then, within the Chrome inspector, insert a breakpoint in the code where the AJAX response is first handled (eg. https://github.com/jquery/jquery/blob/master/src/ajax.js#L579). Then proceed to step through the code, inspecting various return-values to see exactly what is going wrong.
If you are not using something like jQuery to make AJAX calls, then I'd recommend using a framework to avoid possible cross-browser compatibility issues like you might be experiencing right now.

display message on success return in ajax with jquery problem

i am using ajax with jquery .i have written this code:
$.ajax({url:"myurl.php",
data:datastr,
type:"POST",
success:function(data){
$("#msgbx").text(data);
}
});
it done what i want at the backend but doesn't show the return message in div with #msgbx id.
what is the problem?
The problem may be related to the formatting or encoding of your returned JSON object, or it may be a failure on the server that occurs after all your other processing is done, but immediately before you return your data.
Without seeing any other code, try looking at the console window in either Firebug or Chrome's web development tools to see what your server is responding with. You should see an Ajax POST method logged to the console window. Assuming you don't have an error code shown there, check to see what sort of data is being returned (or if any is being returned at all).
If you are getting data back from the server, your problem is in how you're displaying that on the page / inserting it into the DOM. If on the other hand you aren't returning anything, you'll need to check your PHP code to see where other problems might exist in your logic.
Feel free to add more to your post so we can give more specific answers.
use $("#msgbx").html(data);

Django: How to track down a spurious HTTP request?

I have 3 AJAX functions to move data between a Django app on my website and some JavaScript using YUI in the browser. There is not a major difference between them in terms of their structure, concept, code, etc. 2 of them work fine, but in the 3rd one, I get one spurious HTTP request immediately after the intended request. Its POST data contains a subset of the POST data of the intended request. The request meta data is identical except for the CONTENT_LENGTH (obviously) and the CONTENT_TYPE which is 'text/plain; charset=UTF-8' for the intended and 'application/x-www-form-urlencoded' for the unwanted request. I do not set the content type explicitely at all which seems to suggest both requests do not have the same origin and the second one just pops out of thin air.
The intended request sets HTTP_CACHE_CONTROL': 'no-cache' and 'HTTP_PRAGMA': 'no-cache', the spurious one does not. The dev server log output for both requests is
[15/Feb/2010 15:00:12] "POST /settings/ HTTP/1.1" 200 0
What does the last 0 at the end mean ? Could not find any documentation on that. This value is usually non-zero... In Apache, it is the total size in bytes of the server response, can someone confirm it's the same for Django ?
My problem obviously is to find out where this additional request comes from.
I am fairly familiar with JS debugging using Firebug and I think I'm good at Python and Django, but I do not know a lot about the internals of HTTP requests and responses. I can breakpoint and step through the JS code that sends the intended XMLHTTP request, but that breakpoint does not get hit again.
The problem occurs with both FF3 and Safari, I'm on Snow Leopard, so I can't test with IE or Chrome.
I've looked at Django debugging techniques and tools like http://robhudson.github.com/django-debug-toolbar/ but I think I already have the information they can give me.
Can someone advise on a strategy or a tool to narrow the problem down ?
The problematic AJAX function submits form data, the working two don't. Forms have a default action which takes place when the form is submitted: post a request with the form data. I failed to prevent this default action.
So the spurious request did indeed come out of the dark underwood of the browser, there is no code in my js files that sends it.
Solution:
YAHOO.util.Event.preventDefault(event);
at the beginning of the form submit event handler.
See also http://developer.yahoo.com/yui/examples/event/eventsimple.html

Resources