title: How to pass data to a Javascript (!) that is called via ajax?
body: <p>I have a validation-javascript for a form, that is called via AJAX und gives back a result. In the AJAX-Call I pass some data-parameters, but I don't know how to read these in the validation-script. </p>
  
  <pre><code>...
  $.ajax({
              url: validation.js",
              dataType: "script",
              data: { validate: 'true' },
              success: function () {
  ...
  </code></pre>
  
  <p>In the validation.js I want to read the parameter validate, like I would when I was calling PHP ($_GET['validate']).</p>
  
  <p>Is that possible? In the Browser-console, I can see, that the script is called with "validation.js?validate=true", but how can I access validate in the Javascript?</p>
  
  <p>It is really hard to look up, because all I find is "Passing Parameters to/from PHP" and "getting Parameters with JS by url-substring-stuff"..</p>
  
  <p>Thank you,</p>
  
  <p>Paco</p>
  
  <p><em>EDIT</em>
  What I was trying to do: 
  extend a working Javascript with a (client-side) validation-function, that can be extended over time, without touching the rest of the script.
  And I wanted to use the success-callback of the AJAX-call to react to the validation-result.</p>
  
  <p>main.js</p>
  
  <pre><code>// validate Input on update
    $.ajax({
      url: validation.js",
        dataType: "script",
        data: { validation: validation },
          success: function () {
            var result = validate();
              // validation not successful
              if (!result.valid) { ... }
  </code></pre>
  
  <p>validation.js</p>
  
  <pre><code>function validate() {
  
      var result = {
          valid: true,
          data: ''
      };
  
      if(foo) {
          result.valid = false;
          result.data = "There was an error: ...";
      }
      return result;
  
  }
  </code></pre>
  
  <p>This was my first idea and it worked well, apart from the data-parameter in the AJAX-Call, which came later and which I couldn't evaluate. 
  But I guess this still is xy-problem and there is a better and easier way with just writing a function as @quentin suggested..</p>