I'm looking to build an api with a meteorjs app ,so I need to render juste a text , without any HTML.
is it possible with meteorjs ?
so I looked Iron router, and it was easy to render a server side response
simply by placing this code in the server
Router.route("path/view", function() {
this.response.end("ok");
}, {
where: "server"
});
to test on the browser simply http://localhost:3000/path/view will render just "ok"
I found this on https://themeteorchef.com/snippets/server-side-routes-with-iron-router/#tmc-what-is-a-server-side-route
Related
I'm creating a POC using google app maker. I plan on using a JS library that has a dependency on Jquery. I've listed JQuery as an "external resource" to start with and added an H1 element on my html with the following code as part of a client script:
$(document).ready(function(){
$("h1").click(function(){
console.log("jquery works");
});
});
When I preview my app and click on the element, nothing is logged. When I inspect the elements, I can see both the Jquery library and the code above, but the event is not triggering when I click on the element. Any suggestions? The ultimate goal is to be able to use https://querybuilder.js.org/ within the app I'm creating.
My best guess is that when you say that you added the code:
$(document).ready(function(){
$("h1").click(function(){
console.log("jquery works");
});
});
to the client script, what you did was created a client script under the SCRIPTS section of App Maker and then added the code there. If that is so, that is why it's not working.
What you need to do is to use client scripting in the widget event handlers. Each widget has event handlers and the HTML widget is not an exception. What I recommend is to add the code to the onAttach event handler of the HTML widget:
}
Also, you can get rid of the document.ready part and just use the code you see in the image above. That should do the trick.
BONUS: If you will be using classes and ids, for it to work you will need to use the allowUnsafeHtml option:
I hope this helps for now. If you need something else, I'll be happy to help you.
I am new to DOJO and have a requirement where in we need to embed already running website on our new website using an iframe. Both websites will be running on same domain.
I tried using dojo/request/iframe, and am able to see the website in my iframe BUT when clicking on any of the link in embedded website, it opens in another window. But i want it to work in my iframe internally.
Below is the code snippet:
<script>
require(["dojo/request/iframe", "dojo/dom", "dojo/dom-construct"], function(iframe, dom, domConst){
iframe("http://localhost:8080/phpkbv8/", {
handleAs: "html"
}).then(function(data){
var greetingNode = dom.byId('siteInclude');
domConst.place(data.documentElement,greetingNode);
}, function(err){
var greetingNode = dom.byId('siteInclude');
domConst.place('<p>Error Occured!!!</p>' + err,greetingNode);
});
// Progress events are not supported using the iframe provider
});
</script>
Please help me in making it work. Looking for help.
If you are intending to embed an iframe into your page for display/interaction purposes, you shouldn't really be using dojo/request/iframe to do so. If you need to create the iframe programmatically, use DOM APIs or dojo/dom-construct. For example, based on your code above:
domConst.create('iframe', {
src: 'http://localhost:8080/phpkbv8/'
}, greetingNode);
dojo/request/iframe is specifically intended as a transport for sending Ajax requests, in cases where XHR, script injection, etc. aren't sufficient.
I've implemented an SPA for my asp.net project, which is working fine, but this project is running with an api, and the help pages for that api are hosted on /help but the ui-router is taking over this route;
by $urlRouterProvider.otherwise('/'); i can have the url working but I have to manually reload to page for getting it.
Is there any possibility to get this working?
So ignoring the route?
Say to reload the page everytime a link is clicked in a specific url?
Suggestions?
Also I don't have access to the code in that url
If you want to reload ui-route, You can use this code
$state.transitionTo($state.current, {}, { reload: true, inherit: false, notify: true });
You can write your own state name which will be reload, Change the $state.current to your own state name.
OR Some example here
$stateProvider.state('url', { url: '/url?url' })
$state.transitionTo('url', { url: 'http://google.com' })
hopefully things are more clear now. https://github.com/angular-ui/ui-router/wiki/URL-Routing
Fixed it finally:
by adding this code to my landingController it reloads the page when clicked on a /Help link:
$('a[href*="Help"]').click(function () {
location.reload();
});
I have a Meteor app using iron-router which displays rosters in tabs (example here). I would like the URL to include a hash that depends on which tab is showing, ie. http://example.com/myrosters#first.
I have event code like:
Template.roster.events({
'mousedown .nav-tabs li a': function (evt) {
# want to set the URL here
}
});
How do I set the URL here to include a hash, without actually triggering an unnecessary page reload? (I believe Router.go() would trigger a page reload.)
Thanks!
If the path stays the same then it seems go doesn't reload the page.
Router.go(window.location.pathname+"#test3")
When I execute the above, I see no activity in the network tab of the developers console, so I think this should work for your purposes.
Instead of Router.go You Can Use Router.url:
Router.url('yourrouterpathname', {_id: id}, {query: 'q=s', hash: 'hashFrag'});
I'm curious to know whether Meteor would be suitable for following, and how I would go about writing the code.
I'd like to create a webpage, where by the code in a specific "div" can be hotswapped on the fly to users currently looking at that page. (eg. the div contains some text, but then an image replaces it.) Ideally, the swap would be executed manually by the the webpage's admin through the click of a button, or some code fired off on the server or something. Regular viewers to the webpage would not be able to do this - they only see the live changes on the page.
real-life example:
live internet broadcast is off-air, therefore the "div" contains "off-air" text. live hotswap of code happens when broadcast goes on-air, and the viewers of the webpage now see the html5 broadcast player in the "div" instead. later it is swapped back once the broadcast goes off-air.
I'm completely new to the Meteor platform, so I consider myself a newbie :) Any help is appreciated.
You might better off by using a reactive div using data from a collection (I'm going to use an example with raw HTML but you might be better off implementing your own functionality with what content to display instead: i.e
Basically take advantage of reactivity over hot code swaps
Client side html code
<template name="home">
<div>
{{{content}}}
</div>
</template>
js code
if(Meteor.isClient) {
MyCollection = new Meteor.Collection("MyCollection")
Template.home.content = function() {
if(MyCollection.findOne()) {
return MyCollection.findOne().content
}
}
}
if(Meteor.isServer) {
MyCollection = new Meteor.Collection("MyCollection")
//Set an initial content if there is nothing in the database
Meteor.startup(function() {
if(!MyCollection.findOne()) {
MyCollection.insert({content:"<h1>Test content</h1><p>Test Data</p>"
}
}
//A method to update the content when you want to
Meteor.methods({
'updatecontent':function(newcontent) {
id = MyCollection.findOne()._id
MyCollection.update(id, {$set:{content:newcontent}});
return "Done"
}
}
You can update your content either in the mongo collection or with something like (in your web console, client side or server side javascript):
Meteor.call("updatecontent","New content",function(err,result) {
if(!err) {
console.log(result)
}
});
Which will update the code live when you use it.
I'm sorry it's quite long but the bulk of it is setting/updating the html. Its actually much nicer than a hot code swap which would refresh the user's page