Sunday, September 30, 2012

Ubuntu Java with Proxy, Openjdk

Youtube has been blocked in my country, such a lame we are! I don't know how they have blocked , Some sites of google aren't working. I wanted to use the  android sdk to install some of the packages and found out It can't connect. As I am on Ubuntu I tried using the System wide network proxy option but it didn't work. I tried the settings in /etc/environment without result.
At last inserting the proxy settings at /etc/java-6-openjdk/   worked for me.
As I am using the socks proxy , I set the ip and port and it's working for me in both eclipse and android sdk manager.

Sunday, September 16, 2012

wordpress ajax with different WordPress Address and Site Address

If in your WordPress General Settings WordPress address and Site address are different(if two domains are different), using Ajax in the frontend can be a little tricky. Usual approach is to localize a script :

        wp_localize_script('some_script_name, 'SomeVar', array(
                    'ajaxurl' => admin_url('admin-ajax.php')            

and you can get the ajaxurl from your javascript code by SomeVar.ajaxurl 

admin_url('admin-ajax.php') will return an url in respect to the Wordpress address. So, when you make an ajaxcall , it won't work, javascript will throw a cross-domain exception.

The solution is to use the home_url() and appending the ajax url:

        wp_localize_script('some_script_name, 'SomeVar', array(
                    'ajaxurl' => home_url('/').'/wp-admin/admin-ajax.php')           

and don't forget to add the nopriv hook:

add_action('wp_ajax_nopriv_action_name', 'function name');

other wise the frontend ajax won't work, as the request relays back to the WordPress url even if you're logged in as admin the request will not carry that info.

About Me

Web Developer From Dhaka, Bangladesh.