tags:

views:

21

answers:

1

Hi,

I can't get any callback data:

    <script type="text/javascript">
jQuery(function(){
jQuery("#JqPostForm").submit(function(){
        jQuery.post("index.php?option=comp&task=sendemail", jQuery("#JqPostForm").serialize(),

        function(data){
        alert('ok');
            if(data.email_check == 'invalid'){

                    jQuery("#message_post").html("<div class='errorMessage'>Sorry " + data.name + ", " + data.email + " is NOT a valid e-mail address. Try again.</div>");
            } else {
                jQuery("#message_post").html("<div class='successMessage'>" + data.email + " is a valid e-mail address. Thank you, " + data.name + ".</div>");
                }
        }, "json");

        return false;

});
});
</script>

The echo in php function is: echo json_encode($return_arr); which is: {"email_check":"invalid","name":null,"email":null}

but can't get it working i'm developing on localhost and firefox

A: 

Make sure that the server sends the appropriate content type:

header('Content-type: application/json');
kgiannakakis
where I shoul place it?
miojamo
Place it at the top of your PHP file
kgiannakakis
I've done that with no luck
miojamo
I'm sending it to joomla function might that be a problem?
miojamo
You need to make sure that json is actually returned. Use a tool like Fiddler to test the response of the server. Firebug will also help.
kgiannakakis
it looks like it sending in text/html not json? fiddler shows content type text/html
miojamo
I've changed it to json in joomla but still no success
miojamo
Ok I've found a solution first of use index2.php or send in raw format the only function is returned set headers to json
miojamo
// Get the document object. $document = // Set the MIME type for JSON output. $document->setMimeEncoding( 'application/json' );
miojamo