<p>One issue may be that your javascript is requesting a specific url as defined from the site root, thus not giving craft the opportunity to do it's locale routing magic (keep in mind the url for languages other than the default locale may actually be '/no/loadmore.html' — or however you have defined the locale routes in your config settings). So just changing the request url in javascript may solve the problem.</p>

<pre><code>$('.third_article_module').load('loadmore');
</code></pre>

<p>Another thing to keep in mind in general is that you can always specify a locale as part of the query, if you ever need to bypass or override craft's locale routing for some reason.</p>

<pre><code>{% set locale = craft.i18n.getCurrentLocale() %}
{% set entries = craft.entries.section('artikkel').locale(locale).order('dateCreated desc') %}
{% for entry in entries %}
    ...
{% endfor %}
</code></pre>

<p>Another thing worth mentioning is that you could potentially also ajax load content from the current page template by using an <code>isAjax</code> conditional, thus eliminating the need for a separate 'loadmore' template altogether.</p>

<pre><code>{% if not craft.request.isAjax %}
    {# render page content #}
{% endif %}

{% if craft.request.isAjax %}
    {# render loadmore content #}
{% endif %}
</code></pre>

<p>You can then just pass the entry url to your javascript and ajax load the current page (in this case I'm passing the url by defining a 'data-url' attribute on the <code>.showmemore_inner h2</code> dom element; i.e. <code>&lt;h2 data-url="{{ entry.url }}"&gt;</code>).</p>

<pre><code>$('.showmemore_inner h2').on("click", function(e){
    e.preventDefault();
    var url = $(this).attr('data-url');
    $('.third_article_module').load(url);
    $('h2.lasterinn').css('display', 'block');
});
</code></pre>

<p>Note: also <code>e.preventDefault()</code> should come before any <code>return</code> statement or else it will never get a chance to fire.</p>

CC BY-SA 3.0
2015-05-15T20:02:57.507Z
Great! Curious... which one you end up going with?
Douglas McDonald
CC BY-SA 3.0
2015-05-15T13:35:11.203Z
2015-05-15T13:35:11.203Z
Douglas McDonald
<p>I'm having a problem with my ajax-loading when I'm on the english version of my page (My main language is Norwegian). I have a file named loadmore.html that I'm loading in on index.html when pressing a button. The problem is that this page won't show me the English version when I'm on the english version of the site. I really appreciate all your help. There's my code: </p>

<pre><code>$('.showmemore_inner h2').on("click", function(e){
    $('.third_article_module').load('/loadmore.html');
    $('h2.lasterinn').css('display', 'block');
    return false;
    e.preventDefault();
});
</code></pre>

<p>Loadmore.html:</p>

<pre><code>&lt;ul&gt;
    &lt;div class="older_articles_container older_articles_loadmore"&gt;
        {% for entry in craft.entries.section('artikkel').order('dateCreated desc') %}
        &lt;div class="ajax_article" data-id='{{ entry.id }}'&gt;
            &lt;li&gt;
            {% for block in entry.bildekarusell.limit(1) %}
                {% if block.type == "bilde" %}
                    &lt;div id="img_blocks"&gt;
                        {% for image in block.bilde %}
                        &lt;a href="{{ entry.url }}"&gt;
                            &lt;picture&gt;
                                &lt;!--[if IE 9]&gt;&lt;video style="display: none;"&gt;&lt;![endif]--&gt;
                                &lt;source srcset="{{ image.getUrl('hovedsideSekscolBilde') }}" media="(min-width: 990px)"&gt;
                                &lt;source srcset="{{ image.getUrl('hovedsideSekscolBilde2') }}" media="(max-width: 990px) and (min-width: 625px)"&gt;
                                &lt;!--[if IE 9]&gt;&lt;/video&gt;&lt;![endif]--&gt;
                                &lt;img srcset="{{ image.getUrl('hovedsideSekscolBildeMobil') }}" alt="{{ image.title }}"&gt;
                            &lt;/picture&gt;
                        &lt;/a&gt;
                        {% endfor %}
                    &lt;/div&gt;
                {% endif %}    
            {% endfor %}
            &lt;/li&gt;
            &lt;div class="group_sixcol"&gt;
                &lt;li&gt;
                    {% for category in entry.kategorier %}
                        &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;
                    {% endfor %} 
                &lt;/li&gt;
                &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;span class="time"&gt;{{ entry.postDate|date("M Y") }}&lt;/span&gt;&lt;/li&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    {% endfor %}
&lt;/div&gt;
</code></pre>

<p></p>

<p>UPDATE: I tried this code in my _layout.html file but it's not working:</p>

<pre><code>&lt;script&gt;
    $('.showmemore_inner h2').on("click", function(e){
        if ( '{{ craft.i18n.getCurrentLocale() }}' == '{{ craft.i18n.getPrimarySiteLocale() }}' {
            var url = '/loadmore.html';
        } else {
            var url = '/loadmore.html{{ craft.i18n.getCurrentLocale() }}/';
        }

        $('.third_article_module').load(url);
        $('h2.lasterinn').css('display', 'block');
        return false;
        e.preventDefault();
    });            
&lt;/script&gt;
</code></pre>

<matrix><entry><ajax><language><jquery>
Load correct language Ajax
# Load correct language Ajax

(Asked by: username_0 on 2015-05-15)

I'm having a problem with my ajax-loading when I'm on the english version of my page (My main language is Norwegian). I have a file named loadmore.html that I'm loading in on index.html when pressing a button. The problem is that this page won't show me the English version when I'm on the english version of the site. I really appreciate all your help. There's my code: 
$('.showmemore_inner h2').on("click", function(e){
    $('.third_article_module').load('/loadmore.html');
    $('h2.lasterinn').css('display', 'block');
    return false;
    e.preventDefault();
});

Loadmore.html:

    
        {% for entry in craft.entries.section('artikkel').order('dateCreated desc') %}
        
            
            {% for block in entry.bildekarusell.limit(1) %}
                {% if block.type == "bilde" %}
                    
                        {% for image in block.bilde %}
                        
                            
                                
                                
                                
                                
                                
                            
                        
                        {% endfor %}
                    
                {% endif %}    
            {% endfor %}
            
            
                
                    {% for category in entry.kategorier %}
                        {{ category.title }}
                    {% endfor %} 
                
                {{ entry.title }}
                {{ entry.postDate|date("M Y") }}
            
        
    {% endfor %}



UPDATE: I tried this code in my _layout.html file but it's not working:

**Tags:** matrix, entry, ajax, language, jquery


---

## 1 answers

### Answer by username_1 on 2015-05-15. Score: 2 | Accepted answer

One issue may be that your javascript is requesting a specific url as defined from the site root, thus not giving craft the opportunity to do it's locale routing magic (keep in mind the url for languages other than the default locale may actually be '/no/loadmore.html' — or however you have defined the locale routes in your config settings). So just changing the request url in javascript may solve the problem.
$('.third_article_module').load('loadmore');

Another thing to keep in mind in general is that you can always specify a locale as part of the query, if you ever need to bypass or override craft's locale routing for some reason.
{% set locale = craft.i18n.getCurrentLocale() %}
{% set entries = craft.entries.section('artikkel').locale(locale).order('dateCreated desc') %}
{% for entry in entries %}
    ...
{% endfor %}

Another thing worth mentioning is that you could potentially also ajax load content from the current page template by using an isAjax conditional, thus eliminating the need for a separate 'loadmore' template altogether.
{% if not craft.request.isAjax %}
    {# render page content #}
{% endif %}

{% if craft.request.isAjax %}
    {# render loadmore content #}
{% endif %}

You can then just pass the entry url to your javascript and ajax load the current page (in this case I'm passing the url by defining a 'data-url' attribute on the .showmemore_inner h2 dom element; i.e. ).
$('.showmemore_inner h2').on("click", function(e){
    e.preventDefault();
    var url = $(this).attr('data-url');
    $('.third_article_module').load(url);
    $('h2.lasterinn').css('display', 'block');
});

Note: also e.preventDefault() should come before any return statement or else it will never get a chance to fire.

> **Comments:**
> **username_1**: Great! Curious... which one you end up going with?  

---

