bambinou1980 Posted November 25, 2015 Share Posted November 25, 2015 (edited) Hello, I have a quick question please. I am trying to use Ajax for the first time. My form has a delete button as: <a class=\"btn btn-danger delete-button\" id=\"<?php echo $id; ?>\" role=\"button\">Delete</a> When I initiate my ajax call: <script type="text/javascript"> $(function() { $(".delete-button").click(function(){ var element = $(this); var del_id = element.attr("id"); var info = 'id=' + del_id; if(confirm("Are you sure you want to delete this?")) { $.ajax({ type: "GET", url: "delete-record.php", data: info, success: function(){ } }); $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow") .animate({ opacity: "hide" }, "slow"); } return false; }); }); </script> I am getting a dirty url like this in the chrome XHR console: XHR finished loading: GET "http:/websitename.com/admin/crud/payments/delete-record.php?id=%3C?php%20echo%20?%3E" Any idea how to remedy to this please? I tried urlencode($id); but it did not work. Thank you, Ben Edited November 25, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/299581-ajax-calls-using-get-method-causes-bad-characters-in-url/ Share on other sites More sharing options...
Ch0cu3r Posted November 25, 2015 Share Posted November 25, 2015 Because you are using PHP tags within a string your are echo'ing. Remove the PHP tags echo "<a class=\"btn btn-danger delete-button\" id=\"$id\" role=\"button\">Delete</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/299581-ajax-calls-using-get-method-causes-bad-characters-in-url/#findComment-1527141 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.