Jump to content

Ajax calls using GET method causes bad characters in url

Recommended Posts

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() {
var element = $(this);
var del_id = element.attr("id");
var info = 'id=' + del_id;
if(confirm("Are you sure you want to delete this?"))
   type: "GET",
   url: "delete-record.php",
   data: info,
   success: function(){
  $(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
  .animate({ opacity: "hide" }, "slow");
return false;

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,

Edited by Ch0cu3r

Share this post

Link to post
Share on other sites

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>";

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.