php - How to send jquery post request using button -


i trying send post request using jquery. request trying send

$.post("https://api.steampowered.com/ieconservice/declinetradeoffer/v1/", {      key: "1234567891011121314151617181920",      tradeofferid: "$offerid"  }).done(function(data) {     alert("data loaded: " + data); }); 

inside php have $offerid , , key same .

i want send on button click created button inside php

$offerid = $value2['tradeofferid'];  echo '<button id="cancel-offer"> cancel offer </button>';        

how can connect button jquery request , send $offerid request ?

you need select button id attribute, add click handler:

$('#cancel-offer').click(function() {     $.post("https://api.steampowered.com/ieconservice/declinetradeoffer/v1/", {          key: "1234567891011121314151617181920",          tradeofferid: "<?= $offerid ?>"      }).done(function(data) {            alert("data loaded: " + data);     }); }); 

i suggest have quick read through jquery documentation. makes great reference, , gives idea of jquery , not capable of.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -