Sunday, August 1, 2010

JSON reponseText is undefined

Hi
I am sending a Json data from django on an ajax call as A
HttpResponse but i get it as undefined when i try to access it in
javascript
The code is as follows\

Views.py

data=simplejson.dump(dic)
return HttpResponse(data,mimetype='application/json')

Javascript

var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
alert("Here");
ajaxRequest.onreadystatechange = function(data){
alert("ajax");
if(ajaxRequest.readyState == 4){
document.getElementById('State_Over').innerHTML=res.state_name;
document.getElementById('Farming_Rate').innerHTML=res.Farming_Rate;

}
alert("out");
var infoToSend = encodeURI("?
state_id="+id+"&company_id="+document.getElementById('Hidden_Capital1'));
ajaxRequest.open("GET", "http://localhost:8000/Software/update_state/", true);
ajaxRequest.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", infoToSend.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(infoToSend);


PLEASE HELP SOON...
BYE

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment