There are two files, html and jquery. I want to know if possible to connect between these two files.
jquery-test.js:
$(document).ready(function(){
$('#inputForm').submit(function(){
$('#inputForm :text:not("#submit")').each(function(){
var input = $(this).val();
var someData = [];
var weblink = 'http://www.google.com&callback=?'; // just example
$.getJSON(weblink, function(data){
$.each(data.results, function(i, item){
someData.push(item.json_Tag);
});
});
});
});
});
and the HTML file is below:
<html>
<head>
<meta http-equiv = "Content-Type" content = "text/html">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery-test.js"></script>
</head>
<body>
<form method = "post" action = "/result" id = inputForm>
<input type = "text" name = "input" id = input>
<input type = "submit" value = "Search" id = search>
</form>
</body>
</html>
The process is below:
- User key in some word in the text area and press button.
- The jquery will link to “weblink” and catch some data.
- jQuery return these data to HTML file.
- HTML file redirect to /result page with these data.
But I don’t know how can I do the process above ? I don’t know how to return the data form jquery ? I don’t know how to let HTML redirect to other page with data .
Thank you very much.
Javascript (and jQuery, in this case) is designed to run in the user’s browser. You deliver the Javascript to the user by including it in the HTML page.
Include the following in the HEAD section of your HTML document:
Correct your HTML by adding double quotes around the text “inputForm” and all of the other HTML attributes
The jQuery code will now be executed when the user submits the form with ID “inputForm”.