如何做一个onclick AJAX调用到PHP文件,使用jQuery?文件、如何做一个、onclick、AJAX

由网友(对你何止一句喜欢)分享简介:我有一个链接,链接到domain.com,当一个人点击,我希望它做一个Ajax调用counter.php和后2变量,所以它可以增加1到该链接的意见。 I have a link, which links to domain.com , when a person clicks, I want it to do an...

我有一个链接,链接到domain.com,当一个人点击,我希望它做一个Ajax调用counter.php和后2变量,所以它可以增加1到该链接的意见。

I have a link, which links to domain.com , when a person clicks, I want it to do an ajax call to counter.php and post 2 variables to it, so it can add 1 to the views for that link.

我有一个链接:

<a href="http://www.domain.com" onClick="addHit('12345', '1')" rel="nofollow" target="_blank">Link Title</a>

我将如何做到这一点使用jQuery?

How would I do this with jquery?

编辑:

我想是这样的。

function addHit(str, partNumber){
$.get("counter.php", { version: str, part: partNumber })                
}

这似乎工作,但在萤火虫,请求无法完成......只是做了工作...动画。 counter.php回声出来的时候对其做(犯规需要的地方显示出来)一些文本。

It seems to work, but in firebug, the request never completes... it just does that "working..." animation. counter.php echos out some text when its done (doesnt need to show up anywhere).

推荐答案

从jQuery的文档: HTTP://api.jquery .COM / jQuery.ajax /

From the jQuery documentation: http://api.jquery.com/jQuery.ajax/

function addHit(data1, data2)
{
    $.ajax({
       type: "POST",
       url: "http://domain.com/counter.php",
       data: "var1=data1&var2=data2",
       success: function(msg){
         alert( "Data Saved: " + msg ); //Anything you want
       }
     });
}
阅读全文

相关推荐

最新文章