jquery - How to display retrieved data from JavaScript through html -
i know seems kind of vague, best way put words. below example of code.
javascript
<script type="text/javascript"> var name = $('#firstname').val(); var email = $('#useremail').val(); var json = { email: email, firstname: name }; var string = json.stringify(json); $.ajax({ url: 'http://ubuildrewards.api/api/users/getinfo', type: 'get', contenttype: 'application/json', datatype: "json", crossdomain: true, data: string }); </script>
html
<div class="user-logged-in"> <div class="content"> <div class="user-name" id="firstname"> **name here** <span class="text-muted f9">admin</span></div> <div class="user-email" id="useremail"> **email here** </div> <div class="user-actions"> <a class="m-r-5" href="">settings</a> <a href="/first/login">logout</a> </div> </div> </div>
before this, in view have similar javascript code doing login. accessing method userscontroller gets information, , if email , pass correct logs me in. then, method, when logged in want welcome, (name of user logged in as) , current email address (who ever logged in as).
so trying find out how, javascript, paste info retrieved 'getinfo' method, , display name , email put "name here , email here"
i tried descriptive possibly could. sorry confusion. appreciate in advance :) still new jquery , javascript!
why sending login credentials on http , not https (ssl)?
that aside...
you have use .done
method.
$.ajax({ url: 'http://ubuildrewards.api/api/users/getinfo', type: 'get', contenttype: 'application/json', datatype: "json", crossdomain: true }).done(function(data) { console.log("sample of data:", data); $('#firstname').text(data.name); $('#useremail').text(data.email); });
Comments
Post a Comment