title: How to set Ajax URL dynamically?
body: <p>I am working with Laravel 4 and I want to perform validation with Ajax. I have 2 main problems:
  1. The URL at Ajax is static, which means that if I have my app online I should put the URL for online and locally doesn't works
  2. my route is insur_docs/{id} how should be URL for this?</p>
  
  <pre><code>jQuery('form#insur_docs_update').submit(function()
      {
          jQuery.ajax({
              url: "http://localhost:8080/insur_docs/{id}", //my url I don't know how to put it
              type: "post",
              data: jQuery('form#insur_docs_update').serialize(),
              datatype: "json",
              beforeSend: function()
              {
                  jQuery('#ajax-loading').show();
                  jQuery(".glyphicon-warning-sign").hide();
              }
          })
                  .done(function(data)
                  {
                      $('#validation-div').empty()
                      if (data.validation_failed === 1)
                      {
                          var arr = data.errors;
                          jQuery.each(arr, function(index, value)
                          {
                              if (value.length !== 0)
                              {
                                  $("#validation-div").addClass('alert alert-danger');
                                  document.getElementById("validation-div").innerHTML += '&lt;span class="glyphicon glyphicon-warning-sign"&gt;&lt;/span&gt;' + value + '&lt;br/&gt;';
                              }
                          });
                          jQuery('#ajax-loading').hide();
                      }
                  })
                  .fail(function(jqXHR, ajaxOptions, thrownError)
                  {
                      alert('No response from server');
                  });
          return false;
      });
  </code></pre>
  
  <p>routes.php</p>
  
  <pre><code>Route::get('insur_docs/{id}', 'Insur_DocController@edit');
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>public function update($id) {
          Input::flash();
          $data = [
              "errors" =&gt; null
          ];
          $rules = array(
              "ownership_cert" =&gt; "required",
              "authoriz" =&gt; "required",
              "drive_permis" =&gt; "required",
              "sgs" =&gt; "required",
              "tpl" =&gt; "required",
              "kasko" =&gt; "required",
              "inter_permis" =&gt; "required",
          );
          $validation = Validator::make(Input::all(), $rules);
          if ($validation-&gt;passes()) {
              $car_id = DB::select('select car_id from insur_docs where id = ?', array($id));
              $data = InsurDoc::find($id);
              $data-&gt;ownership_cert = Input::get('ownership_cert');
              $data-&gt;authoriz = Input::get('authoriz');
              $data-&gt;drive_permis = Input::get('drive_permis');
              $data-&gt;sgs = Input::get('sgs');
              $data-&gt;tpl = Input::get('tpl');
              $data-&gt;kasko = Input::get('kasko');
              $data-&gt;inter_permis = Input::get('inter_permis');
              $data-&gt;save();
              return Redirect::to('car/' . $car_id[0]-&gt;car_id);
          } else {
              if (Request::ajax()) {
                  $response_values = array(
                      'validation_failed' =&gt; 1,
                      'errors' =&gt; $validation-&gt;errors()-&gt;toArray()
                          );
                  return Response::json($response_values);
              }             
          }
      }
  </code></pre>