Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function getCookie(name) {
- var cookieValue = null;
- if (document.cookie && document.cookie !== '') {
- var cookies = document.cookie.split(';');
- for (var i = 0; i < cookies.length; i++) {
- var cookie = jQuery.trim(cookies[i]);
- // 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;
- }
- var csrftoken = getCookie('csrftoken');
- function csrfSafeMethod(method) {
- // these HTTP methods do not require CSRF protection
- return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
- }
- $.ajaxSetup({
- beforeSend: function(xhr, settings) {
- if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
- xhr.setRequestHeader("X-CSRFToken", csrftoken);
- }
- }
- });
- $('span').click(function() {
- var e = this;
- $.ajax({
- url: '/translate_word/',
- type: "POST",
- data: {wv: $(e).attr('data-wv')}, // или $(e).data('wv'), или $(e).data().wv
- success: function(word) {
- var ru = word.split(';');
- var en_tr = ru[ru.length-1].split('|');
- var en = en_tr[0];
- var tr = en_tr[1];
- var ru_all = '';
- for(var i = 0; i < ru.length-1; i++){
- ru_all += ru[i] + '\n';
- }
- $("h1.ru_wrd").text(ru_all);
- $("h1.en_wrd").text(en);
- $("h1.tr_wrd").text(tr);
- }
- });
- });
- </script>
Add Comment
Please, Sign In to add comment