简体   繁体   中英

Get id from url in modal

In my case, I have a link with this structure:

 {foreach from=$listing item='item'}   
 <div>
                <ul id="saved-tables">
                    <li id="listing_{$item.ID}">
                        <a class="changeModal" href="#">{$item.Side}</a>
                    </li>
                </ul>
            </div>

{/foreach}

When clicking on the link, open modal with select option and save button. After submitting the form need to save in database with (ajax) the new value of select form for defined listing ID. I get the value of select but how to get the ID from the link?

js:

   var $icon = $('#listing_' + id);
   var index = $icon.closest('#saved-tables').find('> li').index($icon);

But can't find the id from this form...

Thanks

You could either supply the id the id to the markup in PHP using $_GET['id'] or you could do it directly in javascript like:

let url = new URL(window.location);
let id = url.searchParams.get("id");
// let id = (new URL(window.location)).searchParams.get("id")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM