Reputation: 493
I couldn't seem to find any examples in the documentation of passing a jquery variable with a load statement. I tried with and without quotes, putting the whole variable statement in, but no luck. Everything else seems to work when debugging, but not passing a variable, please take a look: Edit: I should also make it clear I tried {term: d} and {term: var d} but neither work.
<script>
function callMe() {
for (var i = 1; i< 2; i++){
var b = $('#song'+i).val();
var c = $('#artist'+i).val();
var d = b +" "+ c;
// alert(d);
//$('#results').load('getWeb.php', {term: d});
$('#results').load('getWeb.php', {term: 'd'});
}
// var b = $('#song1').val();
// alert(b);
}
$(document).ready(function(){
callMe();
});
</script>
<form>
Song <input type ="text" name ="song1" id ="song1">
Artist <input type ="text" name ="artist1" id ="artist1"><br />
<input type ='submit' value ='Submit' onClick="callMe();">
</form>
Upvotes: 0
Views: 185
Reputation: 1305
I made an working example for you. A starting point.
<?php
if (isset($_POST['term'])) {
echo $_POST['term'];
exit;
}
?><!DOCTYPE html>
<html>
<head>
<title>Info</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function callMe() {
var b = $('#song1').val();
var c = $('#artist1').val();
var d = b + ":" + c;
$('#results').load('', {term: d});
}
$(function() {
$('form').submit(function() {
callMe();
return false;
});
});
</script>
</head>
<body>
<form action="" method="post">
Song <input type ="text" name ="song1" id ="song1">
Artist <input type ="text" name ="artist1" id ="artist1"><br />
<input type ='submit' name="info" value ='Submit'>
</form>
<div id="results">
</div>
</body>
</html>
Upvotes: 1