0

I want to get $_GET["id"] from the 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);
                }
            }
        });
    });
});

Is it possible to get $_GET[] from the URL with jQuery?

Antti29
  • 2,953
  • 12
  • 34
  • 36
kam
  • 37
  • 7

1 Answers1

0

You can use this function

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, " "));
}

Usage

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

In your code:

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

Just dont forget to define the function beforhand.

void
  • 36,090
  • 8
  • 62
  • 107