Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming your <code>&lt;div class="Welcome"&gt;...&lt;/div&gt;</code> already exists on the page you would replace</p> <pre><code>alert('You are now logged in. You can add additional actions in the js script.'); </code></pre> <p>With</p> <pre><code>$('div.Welcome').html('&lt;span&gt;Welcome...&lt;/span&gt;&amp;nbsp;&lt;a href="/logout"&gt;Logout&lt;/a&gt;'); </code></pre> <p>However, note that I removed <code>{username}</code>. When the user visits the page while logged out they do not have a username. When they log in via AJAX the page is not refreshed, therefore the username still remains on the server side. Zoo Visitor does not return any member data with it, either.</p> <p>It might be better for you to just use a regular log in process than use AJAX if you're trying to do app-like stuff.</p> <p>If you still want to stick to JavaScript for this then one thing you could do is create a template that returns the data via JSON, e.g.</p> <pre><code>{exp:http_header content_type="application/json"} { "username": "{username}" } </code></pre> <p>(Note the use of the <a href="http://devot-ee.com/add-ons/http-header" rel="nofollow">http_header</a> plugin.)</p> <p>Right after a successful login you would use AJAX to check that template, then confirm the results. If <code>username</code> has a <code>length</code> then you know the person is logged in and you can update your Welcome div.</p> <p>Or... you may want to try logging in via <a href="http://www.putyourlightson.net/open-api" rel="nofollow">Open API</a> by Ben Croker. Apparently its authentication returns the member data you're looking for, see <a href="http://docs.eeopenapi.apiary.io/#authentication" rel="nofollow">http://docs.eeopenapi.apiary.io/#authentication</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload