0
4

2 回答 2

1

你似乎很困惑。单击 A 元素将发送 GET 请求,而不是 POST。要模拟单击链接,您可以使用window.location = "<?php echo site_url('main/gmail_invite'); ?>". 要发送浏览器遵循的 POST,您需要使用适当的操作创建一个 FORM 并提交它。

于 2013-04-09T22:32:29.120 回答
0

只需使用 JQuery 的“单击”功能,您就可以操作任何元素并执行您需要执行的任何操作(可以是 GET、POST 或自定义操作)。例如,click 函数可用于提交表单、充当“链接”或简单地触发 Ajax 调用。

这是示例函数:

$('#gmailbutton').click(function(){

var form_data = 'WHATEVER DATA YOUR COLLECTING'
$.ajax({

    //the type of call it can be GET or POST 
    type:'POST',
    //If it is a static URL you dont need to echo with PHP 
    //just write it directly
    url:'main/gmail_invite/ajax.sample.call.php', //or whatever you php file is called

    //if you want to receive the data as html,json,xml
    dataType:'json',
    cache:false,

    beforeSend:function(x){
        //use this only if the response is a JSON object    
        if(x && x.overrideMimeType) {
            x.overrideMimeType("application/j-son;charset=UTF-8");
        }       

    }
}).done(function(response){

    //use "done" rather than "success", as "success" has been deprecated from JQUERY
    console.log( response );
    //no need to return, the ajax returns the call by default

}).fail(function(jqXHR, textStatus, errorThrown){

    console.log( jqXHR );
    console.log( textStatus );
    console.log( errorThrown );

});

});

于 2013-04-10T04:17:45.723 回答