-5
$(document).ready(function () {
  $("#btn").on("change", function() {
    var val = $(this).val();
    $.ajax({
      url: "1.php",
      data: { id: val },
      success: function( result ) {
        alert("Hi, testing");
        alert( result );
      }
    });
  });
});

I want to redirect to 2.php?name=iamchecking it shows alert msg "hi testing" but I want to send it to 2.php and get the value of name from get on PHP. How can I do so?

Mohammad
  • 21,175
  • 15
  • 55
  • 84
  • 1
    `document.location.href="2.php?name=iamchecking";`? – putvande Feb 02 '15 at 13:59
  • http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page ;) – Julo0sS Feb 02 '15 at 14:00
  • `"it shows alert"` - That's what the `alert()` function does, yes. `"i want to send it to 2.php"` - And when you Googled "JavaScript redirect" what did you find? How did that code not work as expected? – David Feb 02 '15 at 14:02
  • @putvande i don't want page to reload. Adding this code reloads the page but i want it not be reloaded. – begineers Feb 02 '15 at 14:03

1 Answers1

1

Just write:

document.location.href = `2.php?name=iamchecking`

That'll redirect user to PHP page with GET arguments.

UPDATE

It is likely impossible to redirect without reloading. You can download content from website and then show it to user, however I don't know is that something what you expect.


However, there is Chrome specific solution to do that:

window.history.pushState(“object or string”, “Title”, “/new-url”);

It could work on other browsers, but doesn't have to.

You can read more, here: http://spoiledmilk.com/blog/html5-changing-the-browser-url-without-refreshing-page/

TN888
  • 7,659
  • 9
  • 48
  • 84