SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why in $.ajax() does not work success: function(html)(document.getElementById)!?

    Hello
    In this code, $.ajax function worked , but success: function(html) does not work(document.getElementById).

    I do not know why it does not work!? What do I do?

    Code:
    $(".submit").click(function(){    
            var entry_id = $("#entry_id").val();
            var comment_body = $("#comment_body").val();
            var comment_name = $("#comment_name").val();
            var comment_email = $("#comment_email").val();
            var comment_url = $("#comment_url").val();
            var dataString = 'entry_id=' + entry_id + '&comment_body=' + comment_body + '&comment_name=' + comment_name + '&comment_email=' + comment_email + '&comment_url=' + comment_url;
            
            if (comment_body == '' || comment_name == '' || comment_email == '' || comment_url == '') {
                alert('Please Give Valide Details');
            }
            else {
                $("#flash").show();
                $("#flash").fadeIn(400).html('<span class="loading">لطفا منتظر بمانید...</span>');
                $.ajax({
                    type: "POST",
                    url: "/zig-co/blog/comment_insert",
                    data: dataString,
                    cache: false,
                    success: function(html){                                    
                        var s1 = document.getElementById('comment_body');
                        var s2 = document.getElementById('comment_name');
                        var s3 = document.getElementById('comment_email');
                        var s4 = document.getElementById('comment_url');
                        $("#update").append(html);
                        $("#update li:last").fadeIn("slow");
                          s1.value + s2.value + s3.value + s4.value;                  
                        $("#name").focus();
                        
                        $("#flash").hide();
                    }
                });
            }
            return false;
        });

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    After looking at your code i can safely say that just adding the values together isn't going to work as your not storing the value anywhere. Also I'm interested to know why your using native JS and not jQuery to retrieve the values.

  3. #3
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank!
    I want after send a message, that message submit online and insert to database, Without Refresh Page...
    For example: Comments with jQuery and Ajax
    Quote Originally Posted by SgtLegend View Post
    After looking at your code i can safely say that just adding the values together isn't going to work as your not storing the value anywhere. Also I'm interested to know why your using native JS and not jQuery to retrieve the values.
    Please tell an example?

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Is there a working demo of your page as feeding examples isn't the best idea when it comes to AJAX.

  5. #5
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is your suggestion? What should I do for this work with jQuery?

  6. #6
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do is document.getElementById for jQuery?
    the for show's value input ($ _POST) as online and without Refresh Page, What do i do?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •