-1

I need to send a parameter from a link to another page that has a text field that calls a .php script and displays information related to the string entered. But if I reach this page passing the parameter by a URL instead of typing it in the text field of the page, the php returns only the json code to the screen. I need to bypass the text field from this url I am trying to build some how. I am trying to do this using ajax, but no success. Any suggestion?

JavaScript:

$(function(){
  $("#textto").keyup(function(){
    var txt = $("#go").attr( $(this).val() );
    $.ajax({
      url: './new_page.php',
      data: {
        'searching' : txt,
        'pam' : 'name',
      },
      success: function(data) {
        alert(data);
      }
    });
  });
});

HTML:

<input type="text" value="" id="texto"/>
<a id='go' href="#">Another Page</a>
thanksd
  • 54,176
  • 22
  • 157
  • 150
Andre
  • 819
  • 3
  • 15
  • 30
  • You mean you want to instead of alerting the data, parse it into the page you are on? There are many answers to "parse JSON html" http://stackoverflow.com/questions/17066636/parsing-json-objects-for-html-table – mplungjan Feb 02 '16 at 16:36
  • Please clarify your question. I cannot understand what's your issue. –  Feb 02 '16 at 16:36
  • your `id="texto"` and `keyup` is on `textto`. – Sumit Sahay Feb 02 '16 at 16:41
  • Page number one has a link to the page two that has a input box, a text filed. The page two works when you type in to the text field, it has a ajax call to php script that returns the results. Now, I am trying to input the search string from a link in another page, page one. Is it a little clear? Thanks! – Andre Feb 02 '16 at 16:44
  • That is not possible. Instead use the URL in the Ajax call and do your own ajax if the page is fromt he same origin. If not forget it. – mplungjan Feb 02 '16 at 16:50
  • Yes, type error, it should be "id="textto". – Andre Feb 02 '16 at 16:52
  • They are two different applications, I am trying to link one to another. Trying to use the search from page one as the parameter of the search on the second page. – Andre Feb 02 '16 at 16:57

1 Answers1

1

The easiest thing is to let a form do it for you, you don't even need js for this:

<form method="get" action="new_page.php">
  <input type="text" name="searching" value=""/>
  <input type="hidden" name="pam" value="name"/>
  <input type="submit" value="Another Page"/>
</form>
Gavriel
  • 18,880
  • 12
  • 68
  • 105