I am trying to makes pagination in django, i need some value (pagesNumber,SearchWord,Categories) to makes some query work,but i cant get my post data from ajax jquery.I have succeeded in running jquery
This my code
CDN
<script src="{% static 'plugins/jquery/jquery.min.js' %} "></script>
<!-- jQuery UI 1.11.4 -->
<script src="{% static 'plugins/jquery-ui/jquery-ui.min.js' %} "></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
scripts
$(document).ready(function () {
$('#submits li').click(function () {
var a = this.id;
linkUrl = 'library/postNewRA/71/' + a + ''
alert(linkUrl);
$.ajax({
type: 'POST',
url: linkUrl,
data: {
'pages': "testValue",
csrfmiddlewaretoken: '{{ csrf_token }}'
},
dataType: jsonp,
success: function (result) {
window.console.log('Successful');//I CANT GET THIS MESSAGES TOO
},
error: function () {
window.console.log('Error!');//I CANT GET THIS MESSAGES TOO
}
});
});
});
views.py
def postNewRA2 (request,raID,page):
pages = request.POST.get('pages',None) # this result "None"
return JsonResponse({"pages":pages})
urls.py
path('postNewRA/<int:raID>/<int:page>',views.postNewRA2,name = "postNewRA2"),
This typo would cause an issue like that
$('#submits li').click(function () {
var a = this.id;
should be
$('#submits li').click(function () {
var a = $(this).attr('id');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.