This is my second attempt in Ajax and I'm not completely sure how to drag it.
That's why I have a modal window that opens when an anonymous user tries to do a certain job window contains a user signup form that I $ $ in my Django login view. If the user name / password is valid, the user is logged in the status code of 1, has been returned as a response. If not, the status of 0 has been returned.
When I try to exclude it from JS, it works, however, within my script, it fails, I think this feedback is done with content_type and how do I I am explaining. I'm not sure.
def login_async (request): If request.method == 'POST' and len (request.POST ['username']) & lt; 20 and len (request.POST ['password']) & lt; 20: Username = request.POST.get ('Username', '') # Possibly the script tag here requires password = request POST.get ('password', '') user = auth.authenticate (user name) = username, password = password) if user has no: auth.login (request, user) status = 1 response = httpResponse () Response ['Content_Type'] = "text / html" response.write (position) return response Other: status = 0 response = HttpResponse () response ['Content_Type'] = "text / html" response. Type (position) return response $ ('input # login'). Click (function (event) {$ .post ("/ Login_async /", {username: $ ('input [name = username]'). Val (), password: $ ('input [name = password]') Val ()}, // $ can also be used (this). To get all form input functions (data) {if (data == 1) {$ ('# login')). Dialog ("off");}}};}); What's the problem here? I initially tried to return the response as JSON but I did not know how to serialise. Cyrilizers ("Jason", position) work. I get an error
One last question ...
If I get a valid status (user is signed), then it will affect the behavior of the modal window on the page. Modal windows open on the basis of login status. If a user signs in, one click opens a set of windows on the click event, and vice versa. This toggle is dependent on the Django reference {% user.is_authenticated%}.
Is this correct only once on the reference page load? Can I do anything to communicate the status change in the modal windows which is safer than simple hacks?
It should be content-type . If your problem is not fixed, then $ Try adding a parameter at the end of the post call. $ Post ("/ login_async /", {}, function (data) {// fancy stuff}, "html");
Comments
Post a Comment