Django ajax

post ajax样例

function getCookie(name) {
            let cookieValue = null;
            if (document.cookie && document.cookie !== '') {
                const cookies = document.cookie.split(';');
                for (let i = 0; i < cookies.length; i++) {
                    const cookie = cookies[i].trim();
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) === (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
function test_ajax(){
	$.ajax({
		url: "#",
		type: "post",
		headers: {
			"X-CSRFToken": getCookie("csrftoken")
		},
		data: {
			"phone": phone,
		},
		cache: false,
	})
}


posted @ 2022-04-22 10:44  lisicn  阅读(13)  评论(0编辑  收藏  举报