Results 1 to 3 of 3

Thread: Remove Style Section as string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    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

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    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
  •  



Click Here to Expand Forum to Full Width