-1

I am trying to add the search string to the api end point and attach it to the call back function.

var searchString;

$("document").ready(function(){

$.get(
    "https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=" + searchString +"&namespace=0&limit=10&origin=*", function (obj) {
        console.log(obj);
        // console.log(obj[1]);
    }
);
});

searchString = function getString(paramtext) {

   console.log(searchString);
   return paramtext;
}
  • Can you show us the request? Go to the `Network` tab of your browser's inspector and give us more information. And show us the HTML as well. – miquelarranz May 16 '18 at 07:08

2 Answers2

0

searchstring is a function. And in that function, you are asking it to console.log itself?

When you want to grab the textbox info, at some point you'll need something like:

searchstring = $("#id-of-textbox").val()

But to be safe, you'll probably want something like:

searchstring = encodeURIComponent($("#id-of-textbox").val())
Kevin
  • 359
  • 2
  • 7
  • 22
0

if you want to add value into search variable.you have simply use

    var search;
search=$('#txtsearch').val();

when txtsearch is search textbox id