asp.net - jQuery, string manipulation : find a tag -
"After a post with $. Ajax () ", sometimes I The server receives an exception. You can see a portion of the HTML below:
& lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; MyMessage & lt; / Title & gt; & Lt; Style & gt; / * ... * / & lt; / Style & gt; & Lt; / Head & gt; & Lt; Body bgcolor = "white" & gt; & Lt; Period & gt; & Lt; H1 & gt; Server error '/' application & Lt; Hour width = 100% size = 1 color = silver & gt; & Lt; / H1> & Lt; H2 & gt; & Lt; I & gt; MyMessage & lt; / I & gt; & Lt; / H2 & gt; & Lt; / Span & gt; & Lt; P & gt; Exception description: & lt; / B & gt; System Exception: Mimese & lt; Br> & Lt; Br> & Lt ;! - ... - & gt; [Exception: MyMessage] Lambda_Math (ExecutionScope, ControllerBase, Object []) +15 9 ... & lt; / Body & gt; & Lt; / Html & gt; I want to get the value of the title tag ("mamsage") how can i do this with jquery?
In short, I do not think you can JQuery only allow you to select those tags Which can be placed in a div tag. Your title tag is not eligible.
See for more information.
Other options ...
Partial HTML :
There are other options. You can return partial HTML whenever you experience any errors. & lt; Html & gt; & Lt; Body & gt; & Lt; P & gt; Error & lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt; Instead of you can & lt; P & gt; Error & lt; / P & gt; .
JSON :
You can also go with some cleaners like JSON. Since you are working with AJAX, you can send the following string back:
{'status': 'failed', 'message': 'something bad happened'} and then access the 'Message' value in your client-side script.
Proxy script :
Using a proxy script, either C # or PHP you can access the value of a title field, and Can return to your jQuery AJAX process.
Iframe method :
Load results in an iframe, and then get the value through iframe.document.title . You can make your IFrame 1x1, so it is not visible.
Comments
Post a Comment