0

I have the following url in codeigniter.

<a href="../add-item-to-wishlist/5/21" class="wishlist_item">Add to wishlist</a>

and I have the following jquery function

<script>
        $(document).ready(function(){
          $('body').on('click', 'a.wishlist_item', function(e){
            $.ajax({
            url:"../add-item-to-wishlist",
            data : "the query string",
                success: function(result){
                    // success code.
                }
            });
            e.preventDefault();
          });
        });
    </script>

how do I get the query string value and pass to the above url ? the add-to-wishlist route redirect to a controller function which take exactly two parameters.

function add_to_wishlist($itemID,$wishlistID = NULL)

What I want to do is call this function using ajax but I dont know how do I call this using ajax

1 Answer 1

1

change your anchor URL to the controller method

href = "add_to_wishlist/5/21"

Then you can do a get request with the full URL

<script>
    $(document).ready(function(){
      $('body').on('click', 'a.wishlist_item', function(e){
        e.preventDefault();
        var obj = $(this);
        $.ajax({
            type:'get',
            url:obj.attr('href'),
            success: function(result){
                // success code.
            }
        });

      });
    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

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.