skip to Main Content

It is my my first time trying to send INPUT text to URL and ALL i want is that when i search something like “cleveland”. It will go as index.php?searchText=cleveland IN the URL.

But the output in the URL is:
index.php?searchText=c?searchText=cl?searchText=cle?searchText=clev?searchText=cleve?searchText=clevel?searchText=clevela?searchText=clevelan?searchText=cleveland.

I can’t find any solutions online so i hope someone can explain this to me on how to fix this.

AJAX code:

function searchFilterInput(page_number) {
  page_number = page_number?page_number:0;
  var search = $('#search').val();
  var getUrl = window.location;
  $.ajax({
    type: 'POST',
    url: 'getData.php',
    data:'page='+page_number+'&search='+search,
    success: function (data) {
// Below doesn't work like it should</b>
    window.history.replaceState("object or string", "Page Title", getUrl+"?searchText="+keywords);
    }
  });
}

2

Answers


  1. Chosen as BEST ANSWER

    Found the answer for people searching it here you go:

    $("#keywords").keyup(function () {
      var keywords = $('#keywords').val(); //searchInput
    var pathname = "?searchText="+keywords;
    history.pushState({}, '', 'products.html'+pathname);
    });
    

  2. You do not need to use ajax for that, in fact you do not even need javascript to do that.

    <form method="GET" action="index.php">
      <input type="text" name="searchText"/>
      <button type="submit">send</button>
    </form>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search