I'm having a bit of a prob开发者_C百科lem investigating the result from my get
in my script. I got the following code to check if a user is still logged in:
$.get("nowhereGet", function(result){
if($(result).find('[id="loginInput"]'))
{
//HTML is in the response then we have been logged out and the user needs to go to
window.location.href = "login";
}
});
Now if the user is logged in Struts will return one html-page in result
from my get. If the user has been logged out different page will be returned one with and element id="loginInput"
in it.
get
? I need a method that performes this check using ajax and any get
or post
done while logged out will get intercepted and the result will be the login-page instead of the intended page$('#result').get(......);
???
UPDATE so the element #result would have what ever the #loginInput has
$('#result').load('login.php #loginInput');
Otherwise look for a json option because the way you are doing it, its kinda messy
Unless you are looking for this
$.get("nowhereGet", function(result){
if(result && $(result).find('#loginInput').length)
{
//HTML is in the response then we have been logged out and the user needs to go to
window.location.href = "login";
}
});
I found an other soloution and with help from Steven Benitez I got it working. Follow the link for more information but in short I let my interceptor do the work instead. If a certain path/action is called the interceptor will return a text stream that I can read from my script.
精彩评论