How can I debug my code using WebMatrix and Visual Studio? - javascript

I am currently writing some code in a question here. The code is employing the fullcalendar JQuery plugin. I am trying to adapt it to use C# and an SQL server as its feed. I have a .cshtml file, which reads from a database, creates a JSON object from the data and returns this to the JQuery plugin.
The kicker for me, is that I am a Java/PHP programmer, who has never worked using JavaScript, C# or Visual Studio before (and probably never will again!) so really I am fighting blind in trying to debug my code. I was hoping someone here could help me to help myself!
At the moment, I am using WebMatrix as an IDE and trying to execute my code after every change. What are better ways that I can test this code?
Edit : I am now using Firebug, it's great! Does anyone have any more tips?

You can do old school print statements using the javascript alerts, http://www.w3schools.com/jsref/met_win_alert.asp , or simply print stuff out as plaintext in the HTML.
Inspired by http://saucelabs.com/blog/index.php/2012/05/goodbye-couchdb/ , I am storing raw JSON to the DB.
WebMatrix has a nice quickref page, http://www.asp.net/web-pages/overview/more-resources/asp-net-web-pages-api-reference.
Mike Brind's book and webpage, http://www.mikesdotnetting.com/Article/160/WebMatrix-Working-With-The-JSON-Helper , are also great references.

Related

Why is VS Code showing an error when I use a jinja2 for loop inside javascript?

I am using Flask do develop a web app to visualize data retrieved from a database. I want to include a chart which requires a Jinja for loop to accomplish population of the chart. When I place the for loop inside the JavaScript <script> tag in an .html document VS Code shows a syntax error. It's fine outside the <script> tag. I tried the exact same code in Eclipse and receive no formatting error. I have also noticed that Jinja text tags such as '{{label}}' can be entered inside JavaScript with no syntax error showing.
screen shot of syntax error in VS Code
I have spent a lot of development time in VS Code and would prefer to not have to switch IDEs at this stage. Any help would be greatly appreciated.
After a bit of experimenting I found the Python Extension Pack by Don Jayamanne. It solved the syntax error problem. I still get some strange color coding, but everything seems to be working. If anyone has a suggestion of a better extension pack, I would love to give it a try.

How to compile Javascript console application locally?

I am a beginner in Javascript, I decided to practice Javascript by problem solving using it, I found an online judge that accepts Javascript V8 4.8.0 code.
So, I searched online to get that version of Javascript V8 on my machine, but I couldn't find any easy way, All the pages were explaining how to build it, and it seems to be a process that I don't need to go through.
Is there an easy way to compile and run command line apps written in Javascript on my machine?
Note: I don't want to use node.js because I tried using it's I/O and
as a beginner I think it is complex in some way.
Update: I found that package manager pbox.me which provides a version of V8 JavaScript Engine and I managed to install it.
Yet another problem appeared: whenever I try to run a js file writing d8 myfile.js in command line nothing happens as if it is an empty program, knowing that I tryied to d8.exe file and it is working, and I made sure the PATH is inserted in the environment variables.
What am I doing wrong?
The easiest way to get started with JavaScript is probably to use it in a browser. You can type simple things directly into the browser's JavaScript console (check the menu); or you can embed your code in a simple HTML document.
If you want, you can even pretty easily implement the readline()/print() functions, so you can pretend to be doing stdin/stdout based I/O: just read from an array of strings, and send output to console.log (or create DOM nodes if you want to be fancy and/or learn how to generate dynamic website content by hand).
Side note: V8 4.8 is severely outdated, don't use it to execute code you haven't written yourself.

Django - Load template with jQuery into variable

I'm working with a client that has a view that, after a user logs in, this view loads a template, that dynamically draws a canvas with jQuery, and generates an image copy of the canvas.
They want to protect the jQuery code, hiding the process in the python code.
I tried using PyExecJS, but it doesn't support jQuery, since there is no DOM.
I've also tried urllib2, mechanize and Selenium, but none worked.
Is there an alternative or have I missed something?
Update/Resolution: In case someone stumbles onto this question: I ended up using Selenium for Python to load the JS function, fed it the necessary data and extracted the image from it. It has a bit of an overhead, but since the main goal was to keep the JS code obfuscated, it worked.
If I understand correctly, you are trying to hide jquery code.
You can't hide jquery code from the user, because django processes python code before it serves up the template, there's no way to protect jquery code with python. Really the best thing you can do is to minimize and obfuscate the code, but that only makes it difficult for human reading.

Problems scraping pages with JavaScript function in python

I'm stuck with a python problem, look.
I have to scrap a page that has JS functions, but that's not the real problem, the real problem is that the information I need is provided by the function.. So I need to run the function to make sure it'll build the HTML code that I need, and then work on it to get what I want..
Just to make sure i'm clear, the JS function build the HTML code, but when I scrap it, it doesn't get HTML buid, it just return the JS function...
I am using mechanize and beautifulSoup for the scraping process.. does anyone know what do I have to do to emulate the JS function to get the HTML code that I need?
Thanks in advance.
You need a scrapping framework that supports javascript. Selenium is one of them and I got good results using along with BeautifulSoup.
You may want to check PyVirtualDisplay if you are going to use Selenium with Mozilla Firefox.

NetBeans: Javascript Code Completion doesn't work as expected

I've just started using NetBeans (PHP version 7.2 for Mac) and love it so far. One thing that I haven't been able to figure out is how to get Code Completion to work for Javascript files in the same fashion as it does for PHP, CSS and HTML files. For example, if I type "fun" in a PHP file, it'll pop up a box that allows me to choose "function":
If I do the same thing in a Javascript file, I get nada:
I've looked all over the place and I have not found a way to add this functionality. Your help would be greatly appreciated.
For this example, try the Source-> Complete Code command (Ctrl+Space by default).
In any case, the JavaScript editor is currently being rewritten from scratch so better code intelligence is to be expected in the near future.
Edit: I almost forget the most obvious answer... Make sure your file belongs to a loaded project. Code intelligence doesn't work properly outside projects.

Categories

Resources