-1

I was trying to load new php page from one the PHP page using Jquery.

window.location = 'admin-editcp.php'; //no success
$(location).attr('href','admin-editcp.php'); // no success

Checked my browser JS is also enabled. I tried it with Mozila, IE and Chrome.

Then i manage site in dreamweaver and I checked it there via live preview and when i clicked in click event, it loads properly.

But not in the above two methods with 3 browser.

I am confuse that what is missing here????

What I have tried:

  • 1
    `location.href='admin-editcp.php';`? – Professor Abronsius Nov 01 '17 at 07:37
  • hi, I tried all methods but no success. Please read my query again as I have mentioned that all ways work with Dreamweaver but none of the way work when i try with browser – V Partap Singh Salathia Nov 01 '17 at 07:43
  • do you have JQ library in your live website ? this works `$("button").click(function(){ location.href = "https://stackoverflow.com/"; })` – Mihai T Nov 01 '17 at 07:47
  • I think you are confusing client and server side functionality....php cannot do anything on the client side except create content. PHP executes only on the server, if you want to do something with the client then its entirely down to JavaScript. – SPlatten Nov 01 '17 at 07:50
  • hi @SPlatten, you are true. but it does not mean that we cannot load server page with client side scripting... – V Partap Singh Salathia Nov 01 '17 at 07:59
  • @Mihai T, I tested as the direction given by you and it works. I got what is the issue.. I was using $("nav ul li a").click(function(){ ........ } and calling to corresponding function.... Now I only need to replace nav ul li a with proper event. Actually, I want when I click nav->ul->a then the corresponing should executes – V Partap Singh Salathia Nov 01 '17 at 07:59
  • @VPartapSinghSalathia, so why not just use location.reload(); on the client side? Or to redirect, location.href = 'newpage'; – SPlatten Nov 01 '17 at 08:05
  • As, I am trying to use all the ways but its not triggering because my click event is not correct.. $('ul.nav li').on("click", function(){ alert("hi"); location.href = "https://stackoverflow.com/"; //var NavId = this.id; //fxnNavClicked(NavId); }); I am not able to find the correct way to resolve the issue. when i click on a then new page reload – V Partap Singh Salathia Nov 01 '17 at 09:03
  • This is the code $('.nav a').on('click', function(){ alert("hi"); location.href = "https://stackoverflow.com/"; //var NavId = this.id; //fxnNavClicked(NavId); }); Alert is displaying Hi. but the page does not loads – V Partap Singh Salathia Nov 01 '17 at 09:47

3 Answers3

2

You can use 'location.href' for this

location.href = "admin-editcp.php";
Super User
  • 9,448
  • 3
  • 31
  • 47
0

You can use this :

jQuery('#id').on('click', function(){
   // Perform your action on click here, like redirecting to a sign-up url
    window.location='https://www.requiredpageurl.php';

});
Ryan Pereira
  • 173
  • 1
  • 1
  • 11
0

You're allmost correct. It should be:

window.location.href = "admin-editcp.php";
Red
  • 6,599
  • 9
  • 43
  • 85