April 4, 2013
$.ajax doesn't response
Nurhidayat Fembrianto’s Questions:
i have some code here that doesn’t work at all:
<script type="text/javascript">
function get_all(){
var mutation = document.getElementById("mutation");
$.ajax({
url:"http://localhost/mandala/test/xx",
success: function(msg){
mutation.innerHTML = msg;
},
error: function(x,status,error){
alert(status+":"+error);
}
});
}
</script>
<html>
<body>
<input type="button" onclick="get_all()" value="Click">
<div id="mutation">
</div>
</body>
</html>
I don’t think so if there is any problem with my url neither the code. But i hope some body can help me out with this problem.
Your HTML Structure in invalid. At the time of Script execution, it will not find the element. So use this instead.
function get_all(){
$.ajax({
url:"http://localhost/mandala/test/xx",
success: function(msg){
$("#mutation").html(msg); //<!-- jQuery Selector
},
error: function(x,status,error){
alert(status+":"+error);
}
});
}