please help for me wrong code. I have created a ajax onClick function but credit amount do not update. What is the problem ?
<script type="text/javascript"> function togglediv(id) { var div = document.getElementById(id); div.style.display = div.style.display == "none" ? "block" : "none"; } function creditInput(id, amount) { var url = "my_campaigns?cat=ptc_normal"; var amount = $('input[name=amount"]').val(); $.ajax({ type:"GET", url:url, data:amount, cache:false, success:function(data){ document.location = "?cat=ptc_normal&allocate="+id+"&allocation_amount="+amount; } }); } </script>
<div id="ad_id"> <input type="text" id="amount_credit" name="amount"> <a onclick="creditInput(<?php echo $ad['id']; ?>)" href="javascript:void(0);">Pay</a> </div> <button onclick="togglediv(ad_id)">Toggle div</button>
Maybe you missed a quote in:
var amount = $('input[name="amount"]').val();
//-------------------------^----------------
First of all use this :
var amount = $('input[name="amount"]').val();
And then use object like syntax when passing data to server side :
data : {
amount : amount
},
Check this, it will help you.
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.