开发者

Using jQuery Ajax methods display a response from a PHP page?

开发者 https://www.devze.com 2023-03-13 04:20 出处:网络
I\'m trying to implement the Jquery .ajax method to simplify the ajax in my website. Here is the function I\'m working 开发者_开发技巧with:

I'm trying to implement the Jquery .ajax method to simplify the ajax in my website.

Here is the function I'm working 开发者_开发技巧with:

function autoComplete(q, succ)
{
    $.ajax({type:"GET",
        url: "search.php",
        data: "q="+q,
        success: succ
    }); 
}

$('input#auto_results').live('keyup', function() {

    var text = $('input#auto_results').val();       

    autoComplete(text,
        function(data) 
        { 

        alert(data);

        }); 
}); 

The response on the PHP page is simply:

echo "response";

So I figure that it should alert the response when the function is called, on 'keyup'. Sadly, nothing occurs. I must be doing something wrong, I am just not sure what it is.


is "keyup" event firing? do following.

$('input#auto_results').live('keyup', function() {

    var text = $('input#auto_results').val();       
    alert("Keyup event is firing");
    autoComplete(text,
        function(data) 
        { 

        alert(data);

        }); 
}); 

if event is firing. then see firebug console tab

or put error function callback on your code:

function autoComplete(q, succ)
{
    $.ajax({type:"GET",
        url: "search.php",
        data: "q="+q,
        error:function(request, textStatus, err){
           alert(request.statusText);
        },
        success: succ
    }); 
}

you may get near to error.

0

精彩评论

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

关注公众号