schoolcoder
schoolcoder

Reputation: 1654

AJAX using JQuery

I am using the following code in index.html

<html>
<head>
<title>Ajax check</title>
<script type="text/javascript" src="jquery-1.8.3.min.js" /> 

<script type="text/javascript">
$(document).ready(function(){

alert('working...');
$('#ibutton').click(function(e){
e.preventDefault();
alert('double click');      
$.ajax({
url: "page.html",
cache: false,
success: function(){
$("#message").val('ajax working..');
},
error: function(){
$("#message").val('error in the page');
}
});
}); 
});
</script>
</head>
<body> 
<form action="page.html">
<input type="button" id="ibutton" value="click here"/>
<div id="message"></div>
</form>
</body>
</html>

In page.html, the only content is 'working...' when I click the click here button... nothing happens.. what is wrong in the code?

Upvotes: -1

Views: 708

Answers (1)

William Seiti Mizuta
William Seiti Mizuta

Reputation: 7995

The bug is the val function. I think that you want to use text function instead of val:

$("#message").text('ajax working..');

Upvotes: 2

Related Questions