0

I'm dealing with how to send successful response to jquery's iframe post form plugin.

With the help of the source code of the plugin's demonstration, I can see that there is the following code below: (Click here for source)

complete : function (response)
{
    var style,
        width,
        html = '';


    if (!response.success)
    // I've always came to this block! And that is exactly the problem that I have
    {
        $('.message').slideUp(function ()
        {
            $(this)
                .html('There was a problem with the image you uploaded')
                .css({
                    color : '#9c0006',
                    background : '#ffc7ce',
                    borderColor : '#9c0006'
                })
                .slideDown();
        });
    }

    else /***** When is the response successful and when will code come here? *****/
    {
        /*
        following code goes here...
        */
    }
}

The exact question is that when do the response.success will be TRUE? And how should I set it to TRUE with PHP? (Please answer both with and without JSON style)

Mohammad Naji
  • 5,372
  • 10
  • 54
  • 79

1 Answers1

0

when you run ajax and communicate with php. youre going to grab whatever php echoes out and use that. in this case its probably wisest to use json encode. heres a very basic example to give you an idea.

a php file:

echo json_encode(array('success' => true));

now a basic ajax request

$.ajax({url:"ajax.php",success:function(result){
     result = $.parseJSON(result);  // we do this to convert the php into javascript format
     if(result.success){
         alert('this is true');
     }
}});
hamobi
  • 7,940
  • 4
  • 35
  • 64
  • its meant to be a working example. its not going to work if you just copy paste it. your ajax requests wants php to pass it array('success' => true); unless it gets that, its going to be false. – hamobi Jul 25 '13 at 23:59