如何为变量设置条件?

How can I make a condition for a variable?

我在 Opencart 的 'product.tpl' 页面上有一个有效的 GeoIP 检测代码。 如何为变量设置条件? 例子:如果 "city"="London" 那么 php echo "Your city is London".

<script 
   src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"> 
</script>

<div>Country: <span id="country"></span></div>
<div>State: <span id="state"></span></div>
<div>City: <span id="city"></span></div>

<script>
   $.ajax({
   url: "https://geoip-db.com/jsonp",
   jsonpCallback: "callback",
   dataType: "jsonp",
   success: function( location ) {
      $('#country').html(location.country_name);
      $('#state').html(location.state);
      $('#city').html(location.city);
    }
});     
</script>

只需选中城市并插入您需要的消息。

例如

var text = '';

  if(location.city == 'London'){
    text = 'XXX';
  } else {
    text = 'YYY';
  }

  $('#city').parent().after('<p>' + text + '</p>');