0

I can't figure out where the problem is :

here is the script :

<script>
$(".icross").click(function(e){
    e.preventDefault();

    var obj = $(this);

    $.ajax({
     type: "GET",
     url: "supprimer.php",
     data: 'id=' + obj.attr('rel')



success: function(html){  

},

});
</script>

and here is the html code associated :

<a href="#" class="icross" title="Supprimer" rel="80"><i class="fa fa-times"></i></a>

I want ajax to execute supprimer.php?id=80 when I click on the link but it doesn't work.

2
  • 1
    Define "it doesn't work". When you debug this, where/how specifically does it fail? Commented Nov 14, 2016 at 16:54
  • 3
    Looks like you might be missing a comma after data: 'id=' + obj.attr('rel') Commented Nov 14, 2016 at 16:57

1 Answer 1

3

You're missing a comma after this line:

data: 'id=' + obj.attr('rel'),
                             ^

Also, if you don't have your script tag appearing after the element then you need a DOM ready wrapper:

$(function(){
    // code here
});

Side note: unless you have good reason to, I recommend using a data object instead of concatenating like that, because by passing an object, jQuery will handle the URL encoding for you.

data: { id: obj.attr('rel') },
Sign up to request clarification or add additional context in comments.

1 Comment

Commas at the end of an object or array are allowed and ignored (except by ancient versions of IE).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.