0

i'm building my first "pretty url" web site, but when i attempt to run any of the AJAX Request functions, they are not being passed to the correct file (submit.php)

i have 1 file that holds all of the AJAX requests (http://mdloring.com/ezleague/submit.php):

function joinLeague(guild, league) {
    $.ajax({
         type: "POST",
         url: "submit.php",
         data: "form=joinLeague&guild=" + guild + "&league=" + league
       }).success(function( msg ) {
           $('.login_success').css("display", "");
              $(".login_success").fadeIn(1000, "linear");
              $('.login_success_text').fadeIn("slow");
              $('.login_success_text').html(msg);
              //setTimeout(function(){location.reload()},3000);
      });
}

on one of my "pretty url" pages (http://mdloring.com/ezleague/game/counter-strike), i have a button that triggers the above function, but the URL it attempts to pass the request to is: http://mdloring.com/ezleague/game/counter-strike/submit.php , instead of http://mdloring.com/ezleague/submit.php

i'm really lost on this one. help is greatly appreciated.

stoopkid1
  • 114
  • 1
  • 1
  • 9

2 Answers2

3

Its due to the relative URL pattern. Try using absolute URL pattern

url: "http://mdloring.com/ezleague/submit.php" in the AJAX call

raghav
  • 285
  • 2
  • 12
  • thank you raghav, that fixed it. since my JS file is in my root directory, i thought that the 'url' parameter would have been been off of that. – stoopkid1 Mar 23 '14 at 06:28
  • accepted raghav's response for mentioning 'absolute url' vs 'relative url' – stoopkid1 Mar 23 '14 at 06:39
2

You can use absolute paths for your url like

url : "/ezleague/submit.php"

Do not use the server name, so your script is portable to other domains.

ivicaa
  • 605
  • 1
  • 6
  • 17