title: How make a callback with PHP/JQuery/JSONP dynamic (Laravel project)
body: <p>Right now I am working on a widget that I want certain people to put on their sites that will send info to them and get some info back.  Right now, I am having them use the following in their code:</p>
  
  <pre><code>&lt;script src="http://myurl.com/widget/widgetscript.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;div id="example-widget-container"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Within widgetscript.js, I have the following bit:</p>
  
  <pre><code>var jsonp_url = "http://myurl.com/widget/external_widget?callback=?";
  $.getJSON(jsonp_url, function(data) {
      $('#example-widget-container').html("This data comes from another server: " + data.msg);
  });
  </code></pre>
  
  <p>The route that is called here calls a function in my WidgetController.php:</p>
  
  <pre><code>public function external_widget($id) {
  
      $array = Fan::likes_by_city($id);
  
      $data = "{msg:'Hello World!'}";
  
      if(array_key_exists('callback', $_GET)){
  
          header('Content-Type: text/javascript; charset=utf8');
          header('Access-Control-Allow-Origin: http://www.example.com/');
          header('Access-Control-Max-Age: 3628800');
          header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
  
          $callback = $_GET['callback'];
          echo $callback.'('.$data.');';
  
      } else {
          // normal JSON string
          header('Content-Type: application/json; charset=utf8');
          echo $data;
      }
  </code></pre>
  
  <p>I would like this function be dynamic so I can tailor the data in this function for every user that uses the widget (taking the $id as a parameter).  I know I can do this with my route like so:</p>
  
  <pre><code>Route::get('/widget/external_widget/{id?}', array('uses' =&gt; 'WidgetController@external_widget'));
  </code></pre>
  
  <p>Just adding the id parameter to the url.</p>
  
  <p>However, in the code that is placed on the users side (the script and div), I see no way to make this dynamic.  Is there a way to get id data from a script or div that would change the widgetscript.js and thus the route called?  Thank you for your help.  </p>