0

how to get id or idt from URL in Ajax. For example i am on web site index.php?id=1 there is a button which load for example h1.php in this file is a function which needs this id parameter. I can't make this script in Ajax work because can't make URL with proper id, can't get this id from current URL. I tried something like this

<script>
$(document).ready(function () {/* activate scroll spy menu */

    var iconPrefix = '.fa-';

        var id = $(window.location.href).attr('id');
        var idt = $(window.location.href).attr('idt');

    $(iconPrefix + 'mixcloud').click(ajaxDemo);
    ///////////////////* Implementation *///////////////////

    // Demos
    function ajaxDemo() {
        var title = 'Znaczniki H1';

        var params = {
            buttons: [
               { text: 'Close', close: true, style: 'danger' },
               { text: 'New content', close: false, style: 'success', click: ajaxDemo }
            ],
            size: eModal.size.lg,
            title: title,
            url: 'views/h1.php?id='+id+'&idt='+idt,
                  };

        return eModal
            .ajax(params)
            .then(function () { alert('Ajax Request complete!!!!', title) });
    }
  });
  </script>
Mohammad Rahchamani
  • 5,002
  • 1
  • 26
  • 36
  • Id in url? like this `https://example.com/page#title`, if so just use this regex `[^#]+$` to match the id. – BladeMight Aug 06 '17 at 20:15
  • yeap, this work perfect for me var params={}; window.location.search .replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) { params[key] = value; } ); – CommanderSpock Aug 06 '17 at 20:33

0 Answers0