开发者

How do I search results from jquery GET

开发者 https://www.devze.com 2023-03-06 17:42 出处:网络
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:

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.

I thought the above would do the trick but no love. What am I doing wrong?

Is there a better way to do this than to ping the server with a random 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消