I use this code to send a request:
function checkuser() {
$.ajax({
url: 'http://10.252.84.159/ajaxrecivelogin',
//type: 'POST',
data: "{'username': 'aa', 'password' : 'bb'}",
context: this,
dataType: 'json',
success: function (data) {
$("#resp").html("success");
},
error: function ()
{
$("#resp").html("error");
}
});
};
And its worked But when i add type:POST part it cause error.
I use this django code to response that request:
def ajaxrecivelogin(request):
import json
response_data = {}
response_data['status'] = '1'
return HttpResponse(json.dumps(response_data), content_type="application/json")
Is it about my django code?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/006eb711-5f5d-4903-a91b-c68e39a45d29%40googlegroups.com.
I correct my code and it's worked. Thank you guys for your help.
Ajax Code:
function checkuser() {
var myObject = new Object();
myObject.username = $('#username').val();
myObject.password = $('#password').val();
$.ajax({
url: 'http://10.252.84.159/ajaxrecivelogin/',
type: 'POST',
data: JSON.stringify(myObject),
context: this,
dataType: 'json',
success: function (data) {
alert( data.status );
},
error: function ()
{
alert( "Error" );
}
});
};
Django Code:
def ajaxrecivelogin(request):
import json
import ast
x = ast.literal_eval(request.body)
response_data = {}
response_data['status'] = username
return HttpResponse(json.dumps(response_data), content_type="application/json")
And i comment out django.middleware.csrf.CsrfViewMiddleware in setting
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c7b115e-73f8-4a8b-bc38-8bf2ec2481ae%40googlegroups.com.