Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery equivalent of $_SERVER[PHP_SELF]

Tags:

jquery

php

What is the jQuery equivalent of $_SERVER[PHP_SELF]?

I need it so I can insert it into a jQuery function

The jQuery is being called from inside the header

For example I'm trying make a request. This can come from multiple domains hence the need to set it dynamically.

$(".class").load( jQuery equivalent $_SERVER[PHP_SELF] "?page=" + pageNumberID + "&ipp=4" etc);
like image 513
user1711576 Avatar asked Mar 22 '23 00:03

user1711576


2 Answers

Use the properties of the window.location object:

$(".class").load(window.location.pathname + "?page=" + pageNumberID + "&ipp=4" etc);
like image 170
Daniel W. Avatar answered Apr 01 '23 22:04

Daniel W.


You want the name of the JavaScript file you're currently in? It doesn't exist.

Best you can do is window.location.href which gives you the (full) URL of the page you're on.


What you could consider is a serverside script that wraps all your JavaScript files like:

files.add(<?php echo json_encode($filename);?>, function () {
    <?php echo $filecontents;?>
});

This allows your to load JavaScript files as modules or 'widgets'.

like image 38
Halcyon Avatar answered Apr 01 '23 21:04

Halcyon