-
Jun 23rd, 2015, 12:40 PM
#1
Thread Starter
Addicted Member
Remove Style Section as string
Hi There
I have a bit of an issue when handling Ajax Failures
With IIS when you Post to AJAX and it returns a failure the jqXHR.resposeText contains a web page with all the error info on it
Along with the webpage is a whole bunch Of CSS wrapped up in the Style Tags.
The issue is that all i want to do is place that error in to a a different div and display a error Button and if the user wants to see the error they can click on it.
obviously the new CSS takes precendence over all the other CSS and effects a lof of the existing objects.
To remedy this i have decided to remove the Style block from the text
is there a better way to do this?
function ditchStyle(errorMessage)
{
var start = errorMessage.indexOf('<style>');
var end = errorMessage.indexOf('</style>') + 8;
var toremove = errorMessage.slice(start, end);
var str = errorMessage.replace(toremove,"")
return str;
}
Kind Regards
Ian
-
Jun 23rd, 2015, 03:07 PM
#2
Re: Remove Style Section as string
If you need the information in the response, then change the mechanism that generates it so that there is no HTML. The easiest format to work with is JSON. IIS lets you set custom error pages for certain error conditions.
If you are only interested in the response code and not the text then use the 'status' property of the jqXHR object.
-
Jun 23rd, 2015, 03:49 PM
#3
Thread Starter
Addicted Member
Re: Remove Style Section as string
Hi Pengate
thanks for your reply
After much thought i think you are correct, If I'm Handling the Error i can return a proper bit of HTML as opposed to falling back on the AJAX Fail.
Many thanks Again
Ian
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|