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.

March 1, 2012

How to count files in https?

Question by Jan-Dean Fajardo

Is it possible to count files under a directory when you’re only reading to https url? or only possible through ftp?

Answer by Starx

Only through ftp

http & https are protocols to view web applications. Features like directory listing are done from server, not through such protocols.

Explanation in case of php & apache server

When you are using commands like scandir() to read file and directory, its the server that does the reading for you. not any http or https link. The page you browse through such protocols will only deliver the output markup on the page.

Through these protocols, all files except server-side files can be delivered on their actual format.

...

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