Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

django restframework jquery post

$.ajax({
    type:'POST',
    url:'api/v1/comments/',  // switch to the API view url
    contentType: 'application/json',  // tell ajax to send it as `json` content
    data:{
      post_id:$('#post_id').val(),
      origin_path:$('#origin_path').val(),
      parent_id:$('#parent_id').val(),
      csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
    },
    success:function(json){
Comment

django restframework jquery post

$('form').submit(function(e) {
    e.preventDefault();
    if ($(this).parents("tr") != 0) {
        parent_id = $(this).parents("tr").attr("id").split("_")[1];
        data_str = $(this).serialize() + "&parent_id=" + parent_id;
    } else {
        data_str = $(this).serialize();
    }
    $(this).parents("tr").attr("id").split("_")[1]
    $.ajax({
        type: 'POST',
        url: '{% url 'comment_create' %}',
        data: data_str,
        success: function(json) {
            alert(json.message);
            if (json.status == 200) {
                var comment = json.comment.trim();
                var user = json.user;
                if (!json.parent) {
                    $(comment).insertBefore('.table tr:first');
                } else {
                    $(comment).insertBefore('#comment_' + json.parent_id + ' #child_comment:first');
                    $(".replies").text("답글" + json.comment_count + "개 모두 보기");
                }
            }

        },
        error: function(response) {
            alert("some error occured. see console for detail");
        }
    });
});
Comment

django restframework jquery post

<script>
     $('#commentForAjax' ).submit(function(e){
      e.preventDefault();

      $.ajax({
        type:'POST',
        url:'comment/create/',  // make sure , you are calling currect url
        data:$(this).serialize(),
        success:function(json){              
          alert(json.message); 
          if(json.status==200){
             var comment = json.comment;
             var user = json.user;
             /// set `comment` and `user` using jquery to some element
           }             
        },
        error:function(response){
          alert("some error occured. see console for detail");
        }
      });
     });
Comment

django restframework jquery post

    function newModule() {

        var my_data = $("#my_element").val(); // Whatever value you want to be sent.

        $.ajax({
            url: "{% url 'modules' %}",       // Handler as defined in Django URLs. 
            type: "POST",                     // Method.
            dataType: "json",                 // Format as JSON (Default).
            data: {
                path: my_data,                // Dictionary key (JSON). 
                csrfmiddlewaretoken: 
                         '{{ csrf_token }}'   // Unique key.
            },

            success: function (json) {

                // On success do this.

            },

            error: function (xhr, errmsg, err) {

                // On failure do this. 

            }

        });
Comment

PREVIOUS NEXT
Code Example
Javascript :: neo4j get first 3 nodes 
Javascript :: mongoose wont update value in array 
Javascript :: is javascript case sensitive 
Javascript :: angular error ng0303 ngForIn 
Javascript :: platform check in react native for status bar color 
Javascript :: stop monitorevents 
Javascript :: storybook absolute paths 
Javascript :: how to push into an array javascript 
Javascript :: reactstrap img bytes 
Javascript :: express react docker container example 
Javascript :: kjkjl 
Javascript :: how to install node js in plesk 
Javascript :: jquery select2 tab open 
Javascript :: node silent print to themral 
Javascript :: string and charater alphabet order 
Javascript :: how to include build script in node js 
Javascript :: namesandroles javascript 
Javascript :: How can I get or extract some string part from url jquery 
Javascript :: monorepos nx nestjs docker 
Javascript :: selenium python grid configuration json 
Javascript :: No matching version found for swagger-jsdoc@^6.0.0. 
Javascript :: backbone model save without validation 
Javascript :: jest-badges-readme 
Javascript :: how to english paragraph matching in javascript 
Javascript :: javascript date calculations ignore weekends 
Javascript :: dropdown using ajax and django 
Javascript :: npm image to LM hash 
Javascript :: returned data has p tags react 
Javascript :: how to get state value from history react 
Javascript :: underscore js check boolean value 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =