if is ajax,jquery - Not stisfying the condition if request.is_ajax(): in django view - Stack Overflo...

I am trying to Configure the URL and view to check if javascript is calling the view or not using the ajax call.

I am able to Pass this JSON data using AJAX POST method to the django URL.

But in view its not entering in to the condition if request.is_ajax(): it directly goes to the else part in view.

views.py

@csrf_exempt

def lat_ajax(request):

if request.is_ajax():

if request.method == 'POST':

data = request.POST.all()

print data

return HttpResponse(json.dumps({'data': data}), content_type="application/json")

else :

print "you are not in ajax"

return render_to_response('poll/ajax_test.html', locals())

ajax request

var data1 = JSON.stringify(data);

console.log(data1)

//alert(data1)

alert("hi")

$.ajax({

url: "http://127.0.0.1:8000/poll/lat_ajax/",

type:"POST",

data: data,

contentType:"jsonp",

dataType: "jsonp",

success:function(response){

alert ("resp: "+response.data);

alert("you in ajax")

}

});

return false;

});

This html page is not from the same project. I am using the django project url to pass data and then send that data to one email address without saving it. Is this a cross domain problem? In chrome i am getting the error

XMLHttpRequest cannot load file:///C:/test.everycrave.com/contact/contact.php. Received an invalid response. Origin 'null' is therefore not allowed access. contact.html:1

Resource interpreted as Script but transferred with MIME type text/html: "http://127.0.0.1:8000/poll/lat_ajax/?callback=jQuery18102593700629658997_13…1%40gmail.com&subject=Fwd%3A+DB+design&message=sdfsddfsfds&_=1399357203734". jquery.js:3

send jquery.js:3

p.extend.ajax jquery.js:3

(anonymous function) contact.html:256

p.event.dispatch jquery.js:3

g.handle.h

Please help me out.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值