Is it possible to use the attributes action and method in other HTML elements rather than <form>?
The idea is that when the user clicks Account Settings from list Settings (in home page):
I want to load some data from the database using NODE
Modify accountSettings.html
Then load the page
Here is some HTML code (will give Cannot GET /goToSettings error on browser):
<li class="navigation__sub">
Settings
<ul>
<li> Account Settings</li>
<li> Privacy & Security</li>
<li> Notifications & Sounds</li>
<li> User Preferences</li>
<li> Help</li>
<li> Report a problem</li>
</ul>
</li>
app.js
router.post('/goToSettings', (req, res) => {
console.log("PERFORMING CHANGES BEFORE PAGE LOAD");
return res.redirect('/accountSettings.html');
});
I have tried surrounding it with <form> but this will kick the element out of the list, and also doesn't work:
<form action="/goToSettings" method="POST">
<li><a> Account Settings</a></li>
</form>
SOLUTION:
<li><i class="fa fa-user"></i> Account Settings</li>
router.get('/goToSettings', (req, res) => {
console.log("PERFORMING CHANGES BEFORE PAGE LOAD");
return res.redirect('/accountSettings.html');
});
The action and method attribute can only function when being used with a form element. Instead, you could try using an ajax request with a FormData object. It will also not require you to reload the page.
//creates HTTP request and form data object
const xhhtp=new XMLHttpRequest, formData=new FormData();
xhttp.onreadystatechange=function(){
if(this.status===200&&this.readyState===4){
//function to load data based on response
loadData(this.responseText);
}
}
//appends key value pair to formdata
formData.append("KEY","VALUE");
xhttp.open("POST","https://URL",true);
//sends ajax request using formdata
xhttp.send(formData);
I think the method and action attributes are available for <form> elements only
Related
this is one of my first projects with vue.
Basically, I am trying to display an image from a URL from an array.
On the webpage, the URL is in the image back but the actual image is not displaying.
This is in my main vue class
<div id="painting">
<ul v-if="artwork && artwork.length">
<li v-for='(artworks, index) in artwork' :key='index'>
<img v-bind:src="artworks.thumbnailUrl" />
</li>
</ul>
<router-view/>
</div>
then the script code:
<script>
import axios from 'axios';
export default {
data() {
return {
artwork: []
}
},
created() {
axios.get(`http://localhost:9000/artwork`)
.then(response => {
this.artwork = response.data;
})
.catch(e => {
this.errors.push(e)
})
}
}
</script>
This is what it looks like on the web, the url is there but no picture
I have declared a width and a height of the image as well with css
I should mention i getting the information from the database in a node project and connecting by a port number
I am pretty new to stack so I would love any feedback, cheers
From you screenshot code, this looks fine. I can see the image by writing similar HTML
<li>
<img data-v-xcxcc src="http://www.tate.org.uk/art/images/work/A/A00/A00007_8.jpg" />
</li>
https://jsfiddle.net/y2m75usk/
Try clearing your cache or reload the page by Holding the Ctrl key and press the F5 key.
Thanks!
As i html with Router link of Angular 4 how can i set Router in that of backboneJS
html is mentioned below
<ul role="menu" class="sub-menu">
<li><a [routerLink]="['/orderHistory']">History</a></li>
<li><a [routerLink]="['/userprofile']">Profile</a></li>
<li><a [routerLink]="['/addressbook']">Address Book</a></li>
<li><a [routerLink]="['/preferences']">Preferences</a></li>
<li><a [routerLink]="['/wishlist']">Wishlist</a></li>
</ul>
I am using backboneJs and Handlersbar any suggestions or good approach would be so useful. Thanks in advance.
I have to make footer and header in my application.
You can just set the href of <a> as normal hash like:
<li>History</li>
or if your app supports push state, without the hash like:
<li>History</li>
and set up and instance of Backbone.Router as mentioned in the docs.
This router instance will listen to changes in url and invoke the callbacks you define while instantiating the backbone router.
You can do following in your backbone.js View
events: {
'click a': 'changeRoute'
},
changeRoute: function(e) {
e.preventDefault();
var href = $(e.currentTarget).attr("href");
router.navigate(href, true);
}
Im trying to create a link in a view of AngularJS application just to send a data-method DELETE.
My route:
app.delete('/logout', function(req, res) {
req.session = null
res.status(200)
res.redirect('/')
})
My PugJS template:
a(ng-href='/logout', data-method='delete', data-confirm='Are you sure?', rel='nofollow')
span(translate) Logout
The HTML generated:
<a ng-href="/logout" data-method="delete" data-confirm="Are you sure?" rel="nofollow" class="" href="/logout">
<span translate="translate" class="ng-scope">
<span class="ng-scope">Logout</span>
</span>
</a>
But when I follow the link I receive the follow message:
Cannot GET /logout
It's looks to me that the data-method isn`t working. Does some one know what is happening?
Thanks for while.
I suppose you are used to use data-method with Rails. In AngularJS (or HTML), there is no such thing as data-method.
My suggestion is to either write your own directive to send the delete, or to add an action in your controller and use ng-click instead.
Am new to Angular and seek your help. Is it possible to display/load an HTML page (i don't want redirection to a page) through a controller in AngularJS?
To elaborate: I have an application page that displays a list of items, say. Each item has a 'view' icon against it which when clicked should bring up a detailed view of the item.
<ul class="list" data-ng-controller="check">
<li>Item 1
<em class="view"></em>
</li>
<li>Item 2
<em class="view"></em>
</li>
</ul>
myapp=angular.module("MyApp",[]);
myapp.controller("check",['$scope',function($scope){
$scope.somefunction = function(){how to ask it to load an html page i got ??};
}]);
Thanks!
ng-include is the correct way of achieving this. http://docs.angularjs.org/api/ng.directive:ngInclude
If you really don't want to do that you can fetch the page using $http and mark it as safe to render using $sce.
<div ng-bind-html="trustedHtml"></div>
myapp.controller("check",['$scope', '$http', '$sce',
function ($scope, $http, $sce) {
// Fetch contents using $http.
$http({method: 'GET', url: '/someUrl'}).success(function (contents) {
$scope.trustedHtml = $sce.trustAsHtml(contents);
});
}
]);
I'm unsure how to append a Python value into an actual HTML element with JSON and AJAX. This is what I currently have, and below that is the ideal output as a list element. I'm not sure where to include the actual HTML element in the function. Currently it just spits out the unformatted data (obviously).
jQuery
$.ajax({
url: url,
dataType: "json",
data: {'tag_title': tag_title, 'function': 'tag_add'},
success: function(data) {
$('.related-questions ul').html(data['question_title']); }
});
HTML
<li>Why is the sky blue?</li>
Also, ideally I could chain multiple data in the success function into one HTML element, like...
<li>Why is the sky blue?<span>14th December 2011</span></li>
in success function try:
alert($('.related-questions a').html());
Since it seems you're just trying to get some html content for your page, try jQuery's load() function. Instead of sending json back to the browser, your python function could return simple "text/html". For example:
HTML
<ul class="myContainer">
</ul>
Javascript
$("ul.myContainer").load(myUrl, {'tag_title': tag_title, 'function': 'tag_add'});
HTML after:
<ul class="myContainer">
<li>New Content with <b>whatever</b> tags you want</li>
</ul>
Look at .load() here