简体   繁体   中英

Setting jQuery value into c:foreach loop

I am basically trying to get values with an ajax request based on a specific id. I then would like to load the json List returned, and load it into a jstl foreach loop. This is my code for the ajax GET request:

$(this).on("click", ".edit_sighting", function(){
        var username = +$(".edit_sighting").val();
        $.get("${pageContext.request.contextPath}/getSighting/" + username, function(sightings) {

        });
    });

My Button that gets pressed to load these values: So when this is instantiated, I want to load all the sightings that user has into a modal.

<button class="edit_sighting" value="${sighting.username}">Edit Sighting</button>

I want the returned 'sightings' to go into ac:foreach loop to show if the user has more than 1 sighting.

<c:forEach var="" items="${?}">

</c:forEach>

I dont know how to set the jQuery value returned into the 'var' section? Thanks

Try this:

$(this).on('click', '.edit_sighting', function() {
   $.get('${pageContext.request.contextPath}/getSighting/' + $('.edit_sighting').val(), function(sightings) {
                                                                                           $('c\\:forEach').attr('var', sightings);
                                                                                        });
});

Also, why are you using $(this) as a selector when binding the click event?

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