• Home
  • Jobs
  • Courses
  • Teachers
  • For business
  • Blog
  • ES/EN

0

10
Views
How to access $(this) in $.ajax({ }) block?

I want to access clicked button's methods inside ajax' block. I want to make my first game and I am new at javascript please help!

$(document).on("click",".play",function(e){
            e.preventDefault();
            $(this).text("Confirming..");//clicked button I want to access in ajax scope
            stopint();

            //get players' Ids
            var linkText = $(this).attr("href");
            var link = new URL("http://"+linkText);
            var p1 = link.searchParams.get("player1");
            var p2 = link.searchParams.get("player2");
            console.log(p1+","+p2);

            $.ajax({
                url: "matching_player.php",
                type: "POST",
                data: {player1 : p1, player2 : p2},
                success: function(data){
                    $(this).text("Connecting..");//clicked button's text()  
                }
            });
        });
10 days ago ·

Santiago Trujillo

Answer question
Remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Startups
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.