CodeIgniter Forums
Jquery post help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Jquery post help (/thread-33294.html)

Pages: 1 2


Jquery post help - El Forum - 08-21-2010

[eluser]Techno Heart[/eluser]
Hi all,

I am working in a codeigniter project now.

I am trying to delete a reply in a form which has many replies for one question. it is in loop having edit and delete options for all replies.

i want to delete a reply. so in jquery i written one confirmation box. if they click ok using $.post
i will pass id to controller then i will call model. the file is deleting fine. but it is not returning any data to jquery $.post to show the alert success.instead of showing success alert it is showing failure alert. any one here faced this issue…


Jquery post help - El Forum - 08-21-2010

[eluser]vitoco[/eluser]
what's the exact "failure alert"? post some code


Jquery post help - El Forum - 08-21-2010

[eluser]Techno Heart[/eluser]
Code:
$("#delete_topic").live('click',function()
  {
    var diss_id = $("#dissid").val();
        var post_id = $(this).attr('name');
    var parent = $(this).attr('class');
    var path = $("#url").val();
    var url = path+"/discussionforum/deletePost";
    var ok = confirm("Are you sure want to delete this Post?")
    if (ok){
    $.post(url,
    {
         "diss_id":diss_id,
        "post_id":post_id,
        "parent":parent,
         dataType:"html"
    },
    function(html) {
        if (parseFloat(html) == 1)
        {
                  alert('post deleted');
         $('#popupClone').hide();
        location.href = path+"/discussionforum/viewTopic/"+diss_id;
        }    
        else if(parseFloat(html) == 3)
        {
        location.href = path+"/updateresume/allPostsDiscussions";
        }
        else
            {
        alert("try again later");
        location.href = path+"/discussionforum/viewTopic/"+diss_id;
        }
        });
        }
                            
        });

in the above code the condition 1 to be executed if it is deleted successfully. but its coming to else condition saying try again later.


Jquery post help - El Forum - 08-21-2010

[eluser]vitoco[/eluser]
Add to the callback , to see what it's getting returned from the server
Code:
console.log('[['+html+']]')
// OR
alert('[['+html+']]')

and post it


Jquery post help - El Forum - 08-21-2010

[eluser]Techno Heart[/eluser]
Its returning null value..if the query executes correctly it will return 1 else 2. but its returning null. While posting the datas i can see in firbug the url that is passing right..in that its showing red color url.some error telling line 130 in jquery.min.js


Jquery post help - El Forum - 08-21-2010

[eluser]vitoco[/eluser]
try this code
Code:
$("#delete_topic").live('click',function()
{
    var diss_id    = $("#dissid").val();
    var post_id    = $(this).attr('name');
    var parent    = $(this).attr('class');
    var path    = $("#url").val();
    var url        = path+"/discussionforum/deletePost";
    var ok        = confirm("Are you sure want to delete this Post?")
    //
    if(ok)
    {
        $.post(
            url,
            {
                "diss_id":diss_id,
                "post_id":post_id,
                "parent":parent
            },
            function(html)
            {
                alert('[['+html+']]');
                if (parseFloat(html) == 1)
                {
                    alert('post deleted');
                    $('#popupClone').hide();
                    location.href = path+"/discussionforum/viewTopic/"+diss_id;
                }    
                else if(parseFloat(html) == 3)
                {
                    location.href = path+"/updateresume/allPostsDiscussions";
                }
                else
                {
                    alert("try again later");
                    location.href = path+"/discussionforum/viewTopic/"+diss_id;
                }
            },
            html
        });
    }

});



Jquery post help - El Forum - 08-22-2010

[eluser]Techno Heart[/eluser]
the html code u defined in last line
Code:
},html);
is showing error that html is not defined. if i remove that the alert displaying is NaN.


Jquery post help - El Forum - 08-22-2010

[eluser]vitoco[/eluser]
sorry...my mistake

Code:
$("#delete_topic").live('click',function()
{
    var diss_id    = $("#dissid").val();
    var post_id    = $(this).attr('name');
    var parent    = $(this).attr('class');
    var path    = $("#url").val();
    var url        = path+"/discussionforum/deletePost";
    var ok        = confirm("Are you sure want to delete this Post?")
    //
    if(ok)
    {
        $.post(
            url,
            {
                "diss_id":diss_id,
                "post_id":post_id,
                "parent":parent
            },
            function(html)
            {
                alert('[['+html+']]');
                if (parseFloat(html) == 1)
                {
                    alert('post deleted');
                    $('#popupClone').hide();
                    location.href = path+"/discussionforum/viewTopic/"+diss_id;
                }    
                else if(parseFloat(html) == 3)
                {
                    location.href = path+"/updateresume/allPostsDiscussions";
                }
                else
                {
                    alert("try again later");
                    location.href = path+"/discussionforum/viewTopic/"+diss_id;
                }
            },
            "text"
        );
    }

});



Jquery post help - El Forum - 08-22-2010

[eluser]Techno Heart[/eluser]
The alert i am getting is [[]] and as i mentioned early it is going to else block and giving alert try again later.It means its returning null i guess.


Jquery post help - El Forum - 08-22-2010

[eluser]vitoco[/eluser]
the return isn't null, just an empty string ( the return it's 'text' ), meaning that your are not doing any 'echo' in server side.