开发者

Jquery display on link click question?

开发者 https://www.devze.com 2023-01-10 14:14 出处:网络
I want to be able to display the following code below only when a user clicks a 开发者_如何转开发specific link. Is it possible with JQuery? If so how would I be able to do this?

I want to be able to display the following code below only when a user clicks a 开发者_如何转开发specific link. Is it possible with JQuery? If so how would I be able to do this?

Here is my code.

    function signedIN(){
        $.ajax({
            type: "GET",
            url: "http://update.php",
            data: "do=getID",
            cache: false,
            async: false,
            success: function(result) {
                $("#status").text(result);
            },
            error: function(result) {
                alert("some error occured, please try again later");
            }
        });
    }


Given a link with an ID of update:

<a id="update" href="update.php">Update</a>

Bind your signedIN() function to the link's click event:

$('#update').click(signedIN);

You'll need to add a return false; at the end of your function so the link doesn't actually proceed to update.php (the link's href value).

EDIT: here's a more complete code example so you can see how this all comes together:

function signedIN(){
    $.ajax({
        type: "GET",
        url: "http://update.php",
        data: "do=getID",
        cache: false,
        async: false,
        success: function(result) {
            $("#status").text(result);
        },
        error: function(result) {
            alert("some error occured, please try again later");
        }
    });

    return false;
}

$(document).ready(function() {

    // You probably have other jQuery code here, so just place this line somewhere
    $('#update').click(signedIN);

});
0

精彩评论

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