Ajax, jqueryajax
AJAX, Asynchronous JavaScript and XML (Asynchronous JavaScript and XML), a web development technical solution for creating interactive web applications. Asynchronous JavaScript: Use the [JavaScript language] and related [browser class library] functions to send requests to the server. After the server completes processing the requests, [automatically execute a JavaScript callback function ]. PS: the whole process of the above request and response is [secretly], and there is no perception on the page. XMLXML is a markup language. It is one of the formats in which Ajax transmits data during interaction with the background. AJAX can be used: 1. When registering, enter the user name to automatically detect whether the user already exists. 2. When logging in, the system prompts that the user name and password are incorrect. 3. When the data is deleted, the row ID is sent to the background, and the background is deleted from the database. After the database is deleted successfully, delete data rows in the page DOM. Jquery-Ajax 1. Download and import jQuery, put it in the static directory 2. Import the configuration in setting 3. Reference jQuery in HTML
$. Ajax ({url: '/index/', type: 'post', data: {'username': 'Alex ', 'Password': '000000'}, success: function (data) {// This function is automatically executed after return in the background // data is the data returned in the background }})
Let's take a look at the example front-end page: <! DOCTYPE html> View. py in Django
Import jsondef ajax_demo (request): if request. method = 'post': ret = {'status': False, 'message': ''} user = request. POST. get ('user', None) pwd = request. POST. get ('pwd', None) if user = '000000' and pwd = '000000': # return HttpResponse ('1 ') ret ['status'] = True return HttpResponse (json. dumps (ret) else: # return HttpResponse ('2') ret ['message'] = 'user name or Password error! 'Return HttpResponse (json. dumps (ret) return render(request,'ajax_demo.html ')View Code ajax implemented based on jQuery can be said to be the most convenient and easy to use. In fact, jQuery cannot directly respond to ajax, but uses XMLHttpResponse to respond accordingly. XMLHttpResponse is also called Native ajax. For details, see Wu sir's AJAX full set.