简体   繁体   English

使用JavaScript运行ASP代码onclick链接

[英]run an ASP code onclick a link using javascript

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. 目前,我为上述问题编写了ASP经典代码,但速度有些慢。 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 Reload page after click on + Or - . 所以,这是我的问题:我想在该asp代码后使用Ajax代码,以防止单击+或-后重新加载页面。 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 :) 我再一次完成了ASP代码,但想要AJAX :)

in your javascript function rateup() make an ajax call to your classic asp site. 在您的javascript函数rateup()中,对经典的ASP网站进行ajax调用。 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 . 然后在您的javascript函数中更改的onclick事件。

for all this you better use a javascript framework like jQuery. 为此,您最好使用jQuery之类的JavaScript框架。

example code (jQuery and classic asp): 示例代码(jQuery和经典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
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM