jQuery $.ajax()
does not seem to work correctly with IE8 but it is working with Firefox, Chrome and Safari. I am submittin the form and response back in JSON format.
Here is my code:
test.php:
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jsFile.js"></script>
<form action='_test.php' method='post' class='ajaxform'>
<input type='text' name='txt' value='Test Text'>
<input type='submit' value='submit'>
</form>
<div id='testDiv'></div>
_test.php:
<?php
$arr = array( 'testDiv' => $_POST['txt'] );
echo json_encode( $arr );
?>
jsFile.js:
jQuery('.ajaxform').live('submit', function(event) {
$.ajax({
url : $(this).attr('action'),
type : $(this).attr('method'),
dataType: 'json',
data : $(this).serialize(),
success : function( data ) {
for(var id in data) {
jQuery('#' + id).html( data[id] );
}
}
});
return false;
});
Behavior:
In Firefox, Chrome, Safari:
When I submit the form then value of textfield(txt) is successfully populated in DIV(testDiv) without disturbing whole page.
In IE:
When I submit the form then it just shows json form on screen like this: {"testDiv":"Test Text"}
How to solve this problem in IE?
Thanks.