MVC3 - How to dynamically set facebook app Id in javascript? - javascript

I have an MVC3 web app that uses a number of the facebook api calls. When I am testing I am using one facebook app Id but will use another in prod (this will be swapped in during the build).
Ideally I'd like to put the app Id in the web.config file to make swapping it during the build easy and so that the id is only in one place. However, I can't see an elegant way to get the id from the app.config into the multiple javascript functions that need it. I looked at reading it into a variable in the _AppStart.cshtml file but not sure that this is right as it means reading the value into a c# object and then passing that as a string to a javascript function that is called before each page loads and that smells a bit wrong.
I'm still learning javascipt so I'm not sure how this thing "should" be done. Any pointers would be great.
Matt

So, I've just come across this which deals with my question. I thought I'd exhausted google before asking this question but obviously not ;-)
integrating-facebook-login-button-in-aspnet-mvc-4-application

Related

How to access Java information in Javascript

I'm still learning programming, and for one of my assignments I need to create a web page for displaying the positions of some vehicles in a map. While I know Java and a little bit of Javascript, and I'm going to use a data base that I already know (ArangoDB), I'm not sure how to communicate the Java side with Javascript. On Java I created the repository for the data on the DB, with functions like insertEntity, getEntity(key), etc, and I have the structure for those entities in Java too (Vehicle class, BaseEntity class, Position class).
I need to access that information inside of Java with Javascript for displaying it on the map I got (Leaflet, works using JS).
I never created a complete application using different languages, so I'm lost on how to proceed here. While ArangoDB has a JS driver, I wanted to use the Java driver because I like more how you can strcuture objects in that language.
Currently I created a Maven project (first time using it) and I'm using ManagedBean from JSF for accessing some specific data and displaying it on a xhtml page. But I'm just messing around with this, seeing what works out of the box and what doesn't.
Even a reference to a resource for doing this (I'm guessing this falls under web developement) would be appreciated, as until this point the only things we've done are console programs.
Edit 1:
For clarification, the information in the database is being retrived by Java (backend) and I need that information in Javascript for displaying it on the map (frontend).

Where should I place my JS code that interacts with the database

Alright, so ive been fiddling around with Spring Boot recently and built a pretty cool backend. I got a pretty good hang of it, I want to start to mess around with the front end more. So, I want to create a main feed that dynamically updates based on whats in my sql database. It will load a few objects/comments as I get closer to the bottom of the page. Something like the function of reddits system of its main feed. So I know I need to use JavaScript to implament the objects and I cant just use thymeleaf because thymeleaf creates the html on startup. I noticed JQuery and it seems cool but I was thinking, it seems like people put their calls to the server get requests in the public/resources folder. This includes the connection to the database. That just doesnt seem right to me at all, why would you want it to be public? And if it doesnt have to be public how do I do so.
So in summery: How do I server JS files that connect and use my database that can dynamically update my webpage. Also any recomendations on what to use?

Amazon Mechanical Turk: How to use react/redux to implement HIT?

I have implemented a complex interactive HTML form using React and Redux. I want to show this form to mturk workers and retrieve the results as a json string (basically containing the redux state after completion of the form).
After some googling, I see three options how to do this:
1) Use a ExternalQuestion and host it on my own server. However, I can't find an option how to create an ExternalQuestion using the Mechanical Turk web-interface. I only found tutorials that explain how to create such a question using the mturk API. Is there no other way to do this? I want to avoid writing scripts for publishing, retrieving the results and approving the workers myself.
2) Use a pre-defined question type such as "Survey". In this question type I can embed an iframe pointing to my own server where the react app is hosted. Using additional javascript I could retrieve the results from the iframe, store it in a hidden field in the survey and submit that as my final result.
3) Compile my react app, upload the JS and CSS files to my own server, copy the HTML to mturk and reference the JS/CSS from there.
None of these options feels right to me. How can this be done correctly?
I think an ExternalQuestion would be my best bet, but I want to avoid writing my own API calls as bugs could result in money loss.
Option 3 is the typical pattern for this kind of use case.
You can reference your assets and then in your javascript put your submit value in a hidden input within the .
This blog post shows how to achieve a use case like this using Crowd HTML Elements with Amazon SageMaker Ground Truth. It should be a helpful starting point for how to do this using MTurk directly.
Please feel free to reach out to me at samhenry#amazon.com if you get stuck.
Thank you,
Amazon Mechanical Turk

Does C# code contained in Javascript still need to be compiled?

We have a web application built with C# and ASP.NET. I have to reference a few .NET session variables in my JavaScript code, so I use the following line to do so:
var layoutID = '<%=Server.UrlEncode(string.Format("{0}", Session["layout_id"]))%>';
This works just fine. The web application is built and published to our web server. If I want to make a change, a .NET change would require me to compile the changes and publish it to the web server again. If it's a JavaScript change, I can simply edit the js in the .ASPX page and the fix is immediately picked up...no compiling needed.
My question - what if I make a change to this inline C# code contained in JavaScript? Say, for example, I meant to access Session["layoutid"] without the underscore. Could I just edit the .ASPX page on the web server, or will this require compiling just as if it were in a .CS file? I'm guessing since it's C#, I will still need to compile for the change to be picked up. And yes I could just try it and see for myself, but I was hoping someone could give a little insight into what goes on behind the scenes with this inline c# code. And while we're on the topic, is the technique I'm using to access .NET sessions variables in JavaScript the most efficient way to do it?
Bonus question - what is this technique called? I tried searching for an answer but I wasn't sure what to search for other than "in-line c# code JavaScript".
Thanks!
No, changes to ASPX/CSHTML files don't require re-compilation.
Note: whether it is good idea to jump on production server and change random code bypassing source control/testing is question to discuss and answer by your team.

Can a Backbone.js app be progressively enhanced, and crawlable by search engines?

I need to implement an MVC JavaScript framework for my next project, but it's as much as a website as it is a web app. Is it possible to expose the data server-side, then parse the URL to show the 'JS version'?
(I plan on using Rails for server-side code)
I wrote a small blog series on exactly this subject...
The first part introduces the problem and the previous solutions, as well as the current solution: HTML5's PushState (history API)
http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-1-introducing-pushstate/
Part 2 shows how to use progressive enhancement with Backbone, so that when you have your server render HTML you can then have your Backbone code take over the existing HTML content instead of rendering new content:
http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-2-progressive-enhancement-with-backbone-js/
Part 3 is a (slightly blurry) video of a presentation I gave on this subject, at a conference:
http://lostechies.com/derickbailey/2011/10/06/seo-and-accessibility-with-html5-pushstate-part-3-the-video/
And while it's not directly a part of this little series, I also wrote a blog post about using Routers with PushState. The gist of that post is: you don't need a router:
http://lostechies.com/derickbailey/2011/10/17/tips-for-using-backbone-js-routers-with-html5-pushstate/
Hope that helps
Im not really sure if I understand your question the right way. I think you have some data and you want to work with it on the server side using rails and then provide it to your javascript and proceed working with the data? Thats right?
Then yes thats possible. Lets say you have a model called article and you access one article by the following url:
http://site.com/articles/1
then you can add an .xml
http://site.com/articles/1.xml
and you will get xml and of cause Javascript can parse xml. This is the default setting of rails.

Categories