My website has been giving me intermittent errors when trying to perform any Ajax activities. The message I get is
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 '
<!DOCTYPE html P'.
So its obviously some sort of server timeout or the server's just returning back mangled garbage. This generally, unfortunately not always, happe
There is an excellent blog entry by Eilon Lipton. It contains of lot of tips on how to avoid this error:
Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it
Read the comments too. There is a comment of somebody with the same problem: "I solved it changing server idle time of my app pool on IIS. It was only 5, so I incremented it and now works."
"The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server.
Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often).
Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts."
Most common reasons for that error:
Calls to Response.Write():
Response filters
HttpModules
Server trace is enabled
Calls to Server.Transfer()
Probably there is an error occuring on post back. In this case, you can view the details about the error by adding a PostBackTrigger to your updatepanel and referencing the button which causes the problem:
<asp:updatepanel ID="updatepanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="button1" />
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:updatepanel>
I had this happen to me and none of the causes on the list in the answer applied. I didn't find the root of the problem until I disabled my AJAX altogether. Discovered that the code was saving an object to the ViewState that contained an unserializable object. I made the object serializable and it started working again.
Problem: Sys.WebForms.PageRequestManagerParserErrorException will occur when redirecting your page, lets say button click inside UpdatePanel in aspxAjax.
SOlution:
Add a "GoTo" button in your aspx page where update panel is using and add it outside Update panel
In your code assign ur just registered userID to session variable , say Session["UseridJustregistered"]=Id from DB or UsernameField
Respose.Redirect("regSucces.aspx?urlid='" + Session["UseridJustregistered"] + "'");
Check if Session["UseridJustregistered"] is null or not
This is OLD Classic ASP way which can solve our problem , by the time Microsoft find a solution we can tackle it this way.
I solved this exact same problem removing the Content-Type: form the Custom HTTP Headers section in the HTTP Headers tab in IIS. This was breaking the encoding of the page and somehow it affected Ajax in general.
The Content-Type I had configured in IIS was setting the encoding to ISO-8859-1.
This may be a little hacky, but it solved the issue for me. I didn't have any of the common reasons for the error, so I just put in this band-aid in the page load:
if (Session.SessionID == "")
{
Page.Session.Add("SessionID", Session.SessionID);
}
I solved this same problem by removing mistakenly-nested UpdatePanels.
I finally solved my variant of this same problem. I was attempting to copy/move a selected value between 2 listboxes in a webform. In my case, I had to specifically call {listbox}.ClearSelection() prior performing the action the 2nd time around.
So obviously this problem/error message can occur for a multitude of reasons.
Change of the app pool FROM INTEGRATED to asp.net classic solved the problem for me.
In our case the issue was caused by a rewriting proxy on the way. The rewrite modified the content of the update panel response. But this response also contains original size. The rewriting mechanism cannot know that few bytes of the response actually contains original response size and it should also be modified.
The update panel response starts like this:
1|#||4|30502|updatePanel|pnlUpdate| ...
The 30502 is original size of the content which is being updated. Rewriting engine modifies the output, but the size stays unchanged => parser error exception.
I don't see a way how to overcome this issue from the client side. We would need to know how exactly was the content modified and then somehow change the size in the response before UpdatePanel ClientScript starts processing it.
I also got this error. The solution reported by "user1097991" solved it for a while (I was using not-serialized objects on viewstate)
But later the error returned again, now in a random fashion. After some search I got the answer: the viewstate was becoming too large and was been truncated. I disable some viewstates on grids and menus and the problem haven't shown again.
I found that my issue was related to a nul character being rendered in the databinding of a GridView. The expected length of the response wasn't matching the actual length of the response text which resulted in the error being thrown. Once I fixed the data in the database, I no longer got the error. The ultimate fix will be to sanitize the text getting rendered during the RowDataBound event.
Looking through the database, I couldn't see the bad data since SQL Server 2008 doesn't show the text if the nul character (Char(0)) is in the string. In the RowDataBound event of my GridView, I added code to throw an exception for any text that had special characters in it. This is how I found the record that contained the nul characters.
tl;dr - Check for nul characters in the rendered html.
Please also be aware that this can be caused by not properly html encoding what you may be rendering to the page through partial postbacks.
I had exactly the same error.
For me it was
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Missing in the httpModules section of web.config (.Net 3.5 app)
This error seems to may be related to many various things.
Update the ScriptMode to "Release"
<asp:ScriptManager ID="ScriptManager" runat="server" ScriptMode="Release"></asp:ScriptManager>
Related
This topic was raised and discussed hundreds of times. None of them correpond to the case I am facing.Please read below before answering.
I want to use WebView do get some info received from a server response and displayed in WebView but after embedded javascript execution. The wanted info can change in server at any time, purpose is to store this info locally on client side post requests to update it on on-demand basis.
I use WebChromeClient to determine when page is loaded (onProgressChanged = 100%) and JavaScriptInterface to get the HTML content, but I get the source code (with javascripts not executed yet).
The info I want to catch is available only after javascripts execution. Please see attached diagram, it may help to clarify my concern.
If someone was faced to similar issue I would appreciate to know how it was resolved.
Thanks
If you know when that JSON arrives on the page, then you can use WebView.evaluateJavascript and run javascript to extract the HTML.
According to https://stackoverflow.com/a/35917295/2921519 HTML extraction can be done by
new XMLSerializer().serializeToString(document)
If you need the javascript to notify the Android side proactively when the page content changes, then you will need to add a javascript interface according to https://developer.android.com/guide/webapps/webview#BindingJavaScript
I've got an issue that occurs eventually in my website. It uses AJAX requests to get data from the server, which uses Spring MVC.
What happens (intermittently) is that sometimes we got an exception like this one:
org.springframework.web.bind.MissingServletRequestParameterException: Required Integer parameter 'page' is not present
at
This kind of exception occurs in some AJAX POST calls (not only for this case!!) and we still cannot reproduce it to understand what is happening.
For example, in one of the cases the parameter 'page' (used to load content while the user scrolls the page - so it's a required variable) is being sent through an AJAX call that has a 'data' field with the page parameter coming from a form like this:
<input type="hidden" name="page" id="page" value="1">
And a ajax call like this one (both $("#filter") and url are ok):
$.ajax({
type: "POST",
data: $("#filter").serialize(), // serializes the form's elements.
url: _ctx + URL_FILTER,
cache: false
})
The only way we got to reproduce that is by changing its property 'name' to something other than "page". But I guess this is not the case (most users don't even open the developer console...)
I've googled it a lot and I checked every possibility. The enconding is ok:
(Content-Type: application/x-www-form-urlencoded; charset=UTF-8)
The parameters are ok, the AJAX looks ok, everything seems ok... But we cannot find what is going on. We have tried a lot of possibilities but we still couldn't force these exceptions to happen.
One hypothesis we have is that sometimes the AJAX may send empty data blocks, with none of the parameters. But we don't even know whether it's true or not and how to check its veracity.
What are the possibilities? How can it be tested?
EDIT:
We could reproduce one of the ways to get the Exception: Reloading the page repeatedly for some seconds (keeping the reload key pressed for a while). Is there a way to prevent the exception for this case?!
Make the below change to controller's class method for page parameter
#RequestParam(defaultValue = 0) int page.
Or paste the controller method here.
If you are not been able to figure out what is reason behind missing parameter, so you can add
public void controllerMethodName (#RequestParam(required = false) int page)
code in your controller definition which will not throw any exception if parameter is not present in your ajax request.
Are you sure your form isn't being modified at the same time? For example, if your library used to handle the scrolling of the page tries to send the same form in a very short time (the first call updates the form while the second call is serializing it). This might be only on some browsers, not all of them, given that you can't easily reproduce it.
The way data is put back in the form might also be responsible for your problem.
Logging HTTP requests / using analytics would help you identify which requests / user agents are causing issues.
I've looked at several other SO questions about this same error, but they don't seem to quite match what I'm doing.
I'm working up an AngularJS app & trying to do pagination within JSFiddle. When I click on my link, I get an error: {"error": "Please use POST request"}
Most sources say that I need to simply change my form method. But no where am I using GET or POST, so not sure where the hangup is happening. Even tried setting breakpoints, but that didn't help much.
Help would be appreciated!
note- To get the same error message: you need to select "RUN" & then click on the link
When you first link to the jsfiddle it works because the frame shows http://fiddle.jshell.net/enigmarm/L7CSD/6/show/. When you click RUN it posts the form to http://fiddle.jshell.net/_display/ to render your page. Going to http://fiddle.jshell.net/_display/ in the browser (ie: using GET) will give you the error.
You have an href="" which means that clicking it regets the page using the GET verb instead of the post that created the rendered page. Don't put href="" on that or stop it from requesting the page.
This can happen when using a XSS script-blocker like NoScript, which changes cross-site requests from POST to GET.
I ran into a scenario where I was thrown an unexpected behavior only in IE8 browser. IE9 and Firefox browsers work fine. The behavior went like:
User populated a form
On purpose - user leaves a mandatory field blanked
User clicked "Submit button" and browser sent a POST request
Expected behavior - error message is thrown along with data that was already provided. Only mandatory field should be left blanked as we did not provide anything in step 2. But instead I'm getting an error message with previous data lost i.e. form empty.
And note this only happens in IE8. Any suggestions?
I am going to answer this questions myself. So, here's what happened in my scenario. It was a double click problem. But I only clicked the button once. Then how did that happen? Some programmer who worked on this project was handling a form submit where he did another submit using JavaScript. But then how did this work in Firefox or IE9+?
I used Fiddler to go deep into this - I noticed in IE8 browser two requests are sent to the server. But IE9 and Firefox correctly handles this scenario (i.e. learns about double click) and sends only 1 POST request instead of 2.
Technologies used: Spring Framework 2.0, JSP, HTML, JavaScript
Why data is lost has also to do with Server - Spring modifies the session attributes (to be specific it's a formObject which is temporarily removed and re-added) while processing requests. When there's another request at the same time it goes through another pipeline (handleInvalidSubmit) which ends up creating a new formObject and thus destroying old data.
Hope this will help others :)
I am working on a MVC project that is supposed to have one page only, with two zones. On one zone I have a Google Map with markers, and the second zone is populated with the selected marker's details.
The details view has a button that when clicked should change the entire view into edit mode without refreshing the page or redirecting it. I have used two views, for details and edit and with the help of ajaxForm function I am switching back and forth between these two views. I'm adding the ajaxForm on documentready for edit view.
<script type="text/javascript">
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#currentDiv').ajaxForm(function(data) {
$('#currentDiv').html(data);
});
});
</script>
The problem appears when on server-side an error appears while trying to save data from edit view and I want to return to the same edit view with the errors displayed. The ajaxForm handler is not added any more and even if the new values that will try to be saved are ok, the detail view is loaded in another page.
Unfortunately, the use of ajaxForm creates some other problems because I don't have control over the cases when the ajax call fails.
Any ideas on how could I fix this? Is it some other solution to switch between those two views without using ajaxForm and without refreshing the page?
I think there are a couple of different questions that you are asking.
First off, you add jquery handlers to deal with the case when you get a 500 type error from the server.
Something like the following. I suggest taking a look at the docs for more info.
$(document).ajaxError(function(event,jqXHR,ajaxSettings,thrownError){
if (jqXHR.status != 0){
window.location = <error page>
}
}
The second problem seems to stem around error handling of known errors (say invalid input). In this case I suggest the following workflow.
1) User clicks on edit button, taken to edit screen
2) User enters in data, use client side validation to do initial check
3) User submits, user is then taken to the view screen and is shown a
success or error message.
The server response could look like:
public ActionResult Edit(EditModel model){
if (!ModelState.IsValid)
{
return Json(new {successful = false, message = "Failed.."});
}
...
}
On the client side, your form callback should now handle the message and the fact it was successful or not. In my implementation, I used knockoutjs to create a "message" area that I could update and clear. (I created templates, etc).
Remember to use client side validation for the easy field validation stuff.... This will save a trip back to the server.
Yours could be quite simple, by popping up the message returned from the server.
Lastly, document ready only fires when the original document is done loading, never again for an ajax call (at least that is my understanding). Just put that code that is the document.ready at the bottom of the edit page. It will fire after the html it is targeting has already been rendered.
Hope that helps!
I have begun to move away from the asp.net views available in ASP.Net MVC due to some incompatibilities and/or unnecessary complexities when trying to achieve functionalities expected of AJAX enabled sites of the day.
I would recommend moving towards a design where you use "dumb" HTML files, use jQuery to download them using AJAX and drop them into a container (personally I use a div) and then use another AJAX call to gather the data from a controller. There are a number of advantages to this approach:
It establishes a real (not fake) separation between client side and server side code.
Html files can be cached on the client cutting down on the amount of data transmitted.
Binding of the Html elements becomes a client side task achieved using jQuery offloading processing cycles from the server.
Controllers essentially become collections of web methods which means they can be untilized by iPhone and Android apps making mobile deployment easier.
I realize this probably isn't the exact answer you're looking for and this may not be an option for you but my hope is that it will help someone at some point make a decision to move away from mixing HTML and server side code.