I am looking for a solution after trying all different option for 5 hours . I am not a big HTML or Javascript person but I tried.
I have a List coming from the Database which is listings of services. Each Service gets their own unique ID. At the moment I send the ID via the URL but this is not preferable,
Within each list element I have a Picture and button and a link using the persons name.
I tried to use javascript to take the value from a value in the href line and sent that to the url which worked but it seems like the server saw that as a different session and hence the webpage did not display the full editable listing,
This was the script
<script>
function myFunction(test) {
var url = "/portal/vendorlistingsadd";
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Accept", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}};
xhr.send(test);
}
</script>
then did
<a href="#" onclick=myFunction('${serviclist.listing_id}')><img src=${serviclist.picture} alt="" class="img-fluid"></a></div>
other problems I had was due to the same 'name' been on each row in the list, I could not extract the correct one.
So basically the only way I can see it working is to send the data via url .
If anyone has any suggestion I would try each one
Thank you
****UPDATE
<form action="/portal/vendorlistingsadd/editlisting" method="post">
</form>
and the second line
<button class= "btn-lg" name ='${serviclist.listing_id}' type = "submit"> <img src="${serviclist.picture}"/> </button>