my ajax is :
$('#save').click(function(){
$.post("http://127.0.0.1:开发者_如何学Go8080/sss",
function(data){
alert(data);
});
})
and the django view is :
def sss(request):
return HttpResponse('ddddddddddd')
how to get some data from the view 'sss'
thanks
You are running into a cross domain issues. You cannot perform ajax calls to different domains. You could use JSONP instead (look at the Flickr example in the documentation, it demonstrates a cross domain ajax request). Your server needs to send data as JSONP string:
def sss(request):
return HttpResponse('someCallbackName({ Data = 12345 })')
where someCallbackName
should be dynamic and passed as request parameter. An important note is that JSONP works only with GET
methods and not POST
.
a hack to do cross domain scripting is to read the data in using urlopen and returning the data you receive
while on domain1
import urlllib2
def getdata(req)
redirectstr = "http://domain2.com/call/that/returns/data/"
#make call to domain2
resp = urllib2.urlopen(redirectstr)
return HttpResponse( resp.whatever() )
精彩评论