May 4, 2012

jquery POST does not return any result in https

Question by mario

I have a jquery script that just runs fine on http://mysite.com

and looks like this:

Javascript:

$('#form_changePass').live('submit', function() {
    //alert('form_changePass cliked');
    $.POST("_ajaxCall.php", $(this).serialize(),
    function(data){
        var json = eval('('+data+')');
        //alert(data);    
        if(json.message=='alert') {
            $('div.info').hide();
            $('div.alert').show().html(json.string);
        }
        if(json.message=='info') {
            $('div.alert').hide();
            $('div.info').show().html(json.string);
        }
    }
    );
    return false;
})

PHP script:

if ($_POST['formType']=="form_changePass") {
.....
.......
   $arr = array( 'message' => 'info', 'string' => $INFO['updatePass']);
   echo json_encode($arr);
}

Now when I move the domain into https the jquery script is not working anymore. I do not get any return value back. Nothing happens.

I also tried to change the POST to getJSON in the javascript and changed the $_POST to $_GET in the php script but it is still not working.

Anybody a idea?

Answer by Starx

.serialize serializes the form data as a string, so send them using a parameter instead.

$('#form_changePass').on('submit', function() {
    //alert('form_changePass cliked');
    $.POST("_ajaxCall.php", { formData: $(this).serialize() },
    function(data){
        var json = eval('('+data+')');
        //alert(data);    
        if(json.message=='alert') {
            $('div.info').hide();
            $('div.alert').show().html(json.string);
        }
        if(json.message=='info') {
            $('div.alert').hide();
            $('div.info').show().html(json.string);
        }
    }
    );
    return false;
})

And stop using .live() methods, they have been deprecated now. Use .on() methods.

...

Please fill the form - I will response as fast as I can!