使用 jQuery 从 URL 中获取 $_GET[]

来了

我想$_GET["id"]从 URL 中获取

$(document).ready(function(){   
    //TRAITEMENT ENVOIE INVITATION
    $("#amis_commun_liste .afficher_plus_modal").bind('click', function f() {
        var afficher_plus_modal = $(this).attr("class");
        $(this).unbind('click', f);
        $.ajax({
            type: "post",
            url: "voir_profil_includes/func_infos.php",
            data: {
                "afficher_plus_modal": afficher_plus_modal,
                //I want to get here $_GET['id']        
            },
            beforeSend: function() {
                $("#amis_commun_liste .afficher_plus_modal").html("En cours");
            },
            success: function(data) {
                if (data != "success") {                          
                    alert(data);
                }
            }
        });
    });
});

是否可以$_GET[]使用 jQuery 从 URL 中获取

空白

你可以使用这个功能

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

用法

// query string: ?foo=lorem&bar=&baz
var foo = getParameterByName('foo'); // "lorem"

在您的代码中:

 data: {
    "afficher_plus_modal": afficher_plus_modal,
    "id": getParameterByName('id')        
 },

只是不要忘记预先定义函数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章