jquery $.get() help [SOLVED]

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

jquery $.get() help [SOLVED]

Post by s.dot »

Code: Select all

function postAjax(page, threadid)
{
    $.get('includes/ajax/forum_showthread.php_numpages.php', function(dt)
    {
        if (dt == page)
        {
                        //$.post() here
            return false;
        }
        
        return true;
    });
}
What I need this piece of code to do is return true only if the data returned from the $.get() call is not equal to the 'page' var.

However, my browser isn't waiting for the ajax call to complete, and doesn't return anything. How can I get my function to wait on the ajax request to complete before returning?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: jquery $.get() help

Post by s.dot »

OK, I have it working in firefox.

Code: Select all

function postAjax(page, threadid)
{
    var equalTo = (!(cpetsp(page, threadid) == page));
    
    if (!equalTo)
    {
        $.post('includes/ajax/forum_showthread.php_reply.php', $('#frmPost').serialize(), function(data)
            {
                document.getElementById('txtPost').value = '';
                document.getElementById('myPost').innerHTML = data;
                $('#myPost').show('slow');
            });
    }
    
    return equalTo;
        
}
 
function cpetsp(page, threadid)
{
    var html = $.ajax({
        type: "GET",
        url: "includes/ajax/forum_showthread.php_numpages.php",
        data: "threadid="+threadid+"&page="+page,
        async: false,
    }).responseText;
    
    return html;
}
However, it will not work in IE and Opera. I don't know how to get debug info out of IE, but opera tells me..
Inline script compilation
Syntax error while loading: line 27 of inline script at xxxxx :
}).responseText
--------^
Anybody know what this means or how to fix it?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: jquery $.get() help

Post by s.dot »

OK, had a bogus comma after async: false.

Solved!
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: jquery $.get() help [SOLVED]

Post by Kieran Huggins »

not sure exactly what you're going for here, but have you looked at http://jquery.bassistance.de/api-browse ... apFunction ?
Post Reply