开发者

run an ASP code onclick a link using javascript

开发者 https://www.devze.com 2023-03-26 18:46 出处:网络
Aright. First let me describe what I want to do. I\'ve a section on my website that clients comment on articles and they can rate those comments Via + / - links that I used there. When a user rated a

Aright. First let me describe what I want to do. I've a section on my website that clients comment on articles and they can rate those comments Via + / - links that I used there. When a user rated a comment up or down then that user shouldn't be able to rate for that comment any more. at the moment I wrote the ASP classic code for above problem but it's a bit slow. because when user click on link the page must reload to add vote.

so, here is my question: I want to use an Ajax code behind that asp code to prevent Relo开发者_C百科ad page after click on + Or - . something like this when user didn't voted yet

<a onclick='rateup("Comment_ID","user_ID") style="cursor:pointer"> <b> + </b> </a>

and then update to this when user rated already:

<a onclick='alert("You have Already Rated This Comment")' style='cursor:not-allowed;'><span> > + </span></a>

once again I've done with ASP code but want a AJAX :)


in your javascript function rateup() make an ajax call to your classic asp site. implement the necessary function and wehn your done write back a status like "vote successful". then in your javascript function change the onclick event of the .

for all this you better use a javascript framework like jQuery.

example code (jQuery and classic asp):

<script>
function rateup(Comment_ID, user_ID) {
    $.post("myAspSite.asp", {ajax: true, act:"rate", direction: "up"}, function(data) {
        if( data === "" ) {
            // here comes the code for changing the onclick o the <a>
            $(#idOfClickedLink).click(function() {
                alert("You have Already Rated This Comment")
            });
        }
    });
}
</script>

<%
if request.form("ajax") = true then
    ' we have an ajax call:
    callback( request.form("act") )
else
    ' normal page processing
    call main
end if

function callback(act)
    select case act
        case "voteup"
            ' do the voteup stuff
            response.write ""
        case "votedown"
            ' do the votedown stuff
            response.write ""
    end select
end function

' "normal" page:    
function main

end function
%>
0

精彩评论

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