user623990
user623990

Reputation:

Using jQuery to send a variable to an external script and grab the results

I have a basic webpage set up and I would like to use jQuery to send a single variable (user-generated) to a javascript script (external -- well not really, still on the server, just not embedded in the webpage). This script will do a bunch of stuff with the variable and spit out a large array of results. I then need to update my page with the results.

I've done something similar using AJAX to POST stuff to a PHP script, but how can this be done with a JS script?

Upvotes: 1

Views: 98

Answers (2)

Kaustubh Karkare
Kaustubh Karkare

Reputation: 1101

well ... including your script using the following (as opposed to embedding it) will keep your source neat and clean:

<script src="yourscript.js" type="text/javascript"></script>

The file could contain a function which you then call from outside (ie, the actual page source). As JavaScript is executed on the client-side (ie, the browser), downloading the file is unavoidable (unless you take extreme measures like an apache::mod_js, or rewrite the function in PHP). Best to keep things simple and use the above.

Upvotes: 1

Daniel Hunter
Daniel Hunter

Reputation: 2896

<script type="text/javascript" src="path/javascript_file.js"></script>

I think this is more what Kaustubh means. You do not have to put the actual code blocks into the page, just reference it this way.

When the page loads it will also load the javascript file (clean)

you can then call the functions seamlessly.

Upvotes: 0

Related Questions