Using jQuery to load external PHP page

I'm using this code to load pages onclick without reloading the current page:

$(function() {
   $("#tabs a").click(function() {
      var page = this.hash.substr(1);
      $.get(page+".php", function(html) {
         $('#content').html(html)
      });
      return false;
   });
});

The code is working and everything's fine except that it looks for the pages to display within the same path of the current page, for example if the current page is www.mysite.com/index It looks for www.mysite.com/index/page.php and this page doesn't exist because I put my PHP pages in a specific folder how to change the code to make it look for the external pages in the specific folder that I want?

Answers


.get, forms, anchors, etc. will all use relative paths if you give them relative paths. If you want them to use an absolute path, provide an absolute path. Absolute paths begin with a slash /.

For example:

$.get("/" + page + ".php" ...

This of course requires page to be the full path.


Need Your Help

Is This “Idiom” Well-Defined?

c++

Let's say I have a C library that has its own (de)initialization routine, as many of them do.

Check if a row exists in sqlite3?

python sqlite python-3.x sqlite3

How do I properly check if a row exists in my database table using Python 3 and sqlite3?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.