Send post-variable with javascript?

前端 未结 5 1109
逝去的感伤
逝去的感伤 2021-01-05 19:55

Is it possible to send post-variables with javascript? I want id to be sent with post, not get.

window.location.href=\"hanteraTaBortAnvandare.ph         


        
5条回答
  •  旧巷少年郎
    2021-01-05 20:11

    You can do it with an Ajax-request (or use hidden forms) - in that case;

    MooTools example:

    new Request({
        url: 'hanteraTaBortAnvandare.php',
        method: 'post',
        data: {
            'id': '10'
        },
        onComplete: function(response) {
            alert(response);
        }
    });
    

    jQuery example:

    $.ajax({
        type: 'post',
        url: 'hanteraTaBortAnvandare.php',
        data: 'id=10',
        success: function(response) {
            alert(response);
        }
    });
    

    Of course you could do this without external libraries, but they simplify alot!

提交回复
热议问题