How to define and use ajax URL

How to define and use ajax URL

I am trying to create conditional URL for Ajax data pull, but it does not work. Any ideas why that is happening? My code looks like below.

  1. $("#valink").click(function () {   
  2.         $("#valink").removeClass("active");
  3.         var key = $(this).text();
  4.         $(this).addClass("active");

  5.     var currRoute = "../content-url/url.php";     
  6. if(key === "Books") {
  7.         currRoute = "../content-url/url1.php";
  8. } else {
  9. currRoute = "../content-url/url2.php";
  10. }

  11.         $.ajax({       
  12.                  type: "GET",  
  13.                  url: currRoute,  
  14.                  async: false,
  15.                  dataType: "html",
  16.                  data: ({
  17.                     key: key, }),
  18.                  
  19.                  success : function(text){
  20.                                $("#link .section").html(text);
  21.                            }
  22.            });   
  23.    
  24.     });