I have this working code:
<script type="text/javascript">
$(document).ready(function(){
$("input").click(function(){
for (var i=1; i<8; i++)
{
var a = "id="+i;
var b = "#sp"+i;
ajax(a, b);
}
});
function ajax(a, b)
{
$.ajax({
url:"ajax.php",
type:"get",
data:a,
success:function(respond){
$(b).html(respond);
}
});
};
});
</script>
<body>
Numbers: <span id="sp1"></span>|<span id="sp2"></span>|<span id="sp3"></span>|<span id="sp4"></span>|<span id="sp5"></span>|<span id="sp6"></span>|<span id="sp7"></span>
<input type="button" value="Send"/>
</body>
And php:
if (isset($_GET["id"]))
{
echo $_GET['id']+10;
}
Above code is working. I don't understand why below code isn't working:
$(document).ready(function(){
$("input").click(function(){
for (var i=1; i<8; i++)
{
var a = "id="+i;
var b = "#sp"+i;
$.ajax({
url:"ajax.php",
type:"get",
data:a,
success:function(respond){
$(b).html(respond);
}
});
}
});
});
Jquery code ajax as function works well, but without it doesn't work... It is strange for me. Please tell me why.