khromov / wp-wpml-geoip-browser-language-redirect

GeoIP Redirector for WPML (WordPress)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I'm getting javascript error see screenshot

upgernaut opened this issue · comments

Ok I resolved it but not sure if correct way, please check:

  1. First of all I deleted re-declarations of these functions in /lib/geoip-api-php/geoip.inc to prevent the fatal error during ajax request
  • geoip_country_code_by_name_v6
  • geoip_country_code_by_name
  • geoip_country_name_by_name
  • geoip_country_name_by_name_v6
  1. Add var browserLanguage; here var browserLanguage; jQuery.ajax({ type: 'GET', data: {'wpml_geoip' : 1}, async: false, success: function (ret) { browserLanguage = ret.country_code } });

this one is to make variable browserLanguage global

Please check and apply if you find it as a correct solution.

Sorry, can you please explain your solution a little more?
I got the same problem.
Where do you set this global browserLanguage?

@Markusila The browserLanguage issue only appears if the AJAX request to check the current user language fails, add ?wpml_geoip=1 to your site URL and make sure you don't have any errors or just a white screen. For example: http://example.com/?wpml_geoip=1.

http://example.com/?wpml_geoip=1. gives me {"country_code":false}

I can't get it working here https://serveandtravel.com

The problem is, that you can't get variable in the AJAX function if it is not global, so just add a declaration of variable before AJAX function like this.
var browserLanguage;