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)
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');
}
}});