Ad
JSON: Fetch Id From Json While Redirecting Login.html To Homepage.html
In given code, after login from index.html page to homepage.html,
for eg: name = Student
password = 123
then in homepage.html body tag value should be like
<html>
<body id="student1">
this is home page.
</body>
</html>
which can be set from json file. If uname = controller then id should be "cntOne". Help me with some sort of code.
json:
{
"Student" : [ { "uName" : "student1", "upass" : "123", "id":"student1" },], "controller":[{ "uName" : "cntOne", "upass" : "123", "id":"cntOne" },]
}
**index.html:**
<input type="text">
<input type="password">
<button>Submit</button>
**homepage.html:**
<html>
<body id="">
this is home page.
</body>
</html>
Ad
Answer
I've added a snippet here, and use alert to show the changed id of div.
var json = {
"Student": [{
"uName": "student1",
"upass": "123",
"id": "student1"
}]
};
if (json["Student"]) {
$('#myDiv').attr('id', json["Student"][0].id);
alert($('div').first().attr('id'));
} else if (json["controller"]) {
$('#myDiv').attr('id', json["controller"][0].id);
alert($('div').first().attr('id'));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">
</div>
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → when i send data with ajax(jquery) i don't find the values in controller without form in laravel 5.1
- → DropzoneJS & Laravel - Output form validation errors
- → Knockout JS - How to return empty strings for observable fields
- → How to replace *( in a string
- → Get the calling element with vue.js
- → Sent Variable to Controller via Ajax in Blade
- → AJAX folder path issue
- → Onclick with argument causes javascript syntax error
- → KNockout JS - Automatic reload of ajax call
Ad