Can't get search bar results inside JSONP call

Can't get search bar results inside JSONP call


I have recently written a short script to accept input from a search bar for the wikipedia search project, and I also found an example of a JSONP call to the api that works for this project. The only problem is that I cannot seem to put the input-accepting script inside the JSONP request so that the JSONP script can see the variable that I made to capture the user input. My plan is to add this variable into the JSONP call, but it currently is not working. What should I do? I have tried accessing the variable from the JSONP with the input-accepting script both inside and out, and neither works. Here are the two pieces of code that I am talking about:

This is the user search part:


$(’#initSearch’).click(function() {
var usr_search= $(’#userText’).val();

//console.log(usr_search); // used this to make sure the script worked like I thought



This is the JSONP part:


url: '',
type: 'GET',
dataType: 'jsonp',
data: {
 action: 'opensearch',
 format: 'json',
 search: 'soccer',
success: function (data) {


Here is a link to the part of the html that I am working with if that helps:


This is my v:

			dataType: 'jsonp',
			jsonp: 'callback',
      url: ""+searchText,
      success: function(json) {

So try to add to ur v, property jsonp, and
U might change action in your data prop to query…