Error while calling js library using $var in a Python app - javascript

In my python code using web.py, I am trying to call js library in main layout.
Here is the code snippet -
$var js: static/js/jquery-3.4.0.min.js static/js/bootstrap.min.js static/js/material.min.js
However, when I execute the code it gives me this error:
127.0.0.1:51225 - - [04/May/2019 07:05:29] "HTTP/1.1 GET /âModels/js1/bootstrap.min.js"" - 404 Not Found
I have also added screenshot of the code and folder structure as attachment. What I can see is that during the call to library, it adds the special characters â and then instead of single quotes there are double quotes at the end. I suspect this is the problem for the library not found.
I was thinking that this could be because of UTF-8 issues. Hence i went and also updated the encoding standards to UTF-8 both at server and client level. But even this is not solving the problem. Can someone please help with suggestions here. I have been struggling this from last 4-5 days and trying to research everything that could help but not of much use.
I'm using PyCharm for development.
The js library path is correct and it should have been called. If it calls then my js code will be executed. Please suggest if I'm doing something wrong here.

Related

How do I add this JavaScript code to Zapier, to issue a 3rd party gift?

My eCommerce website needs to run JavaScript code so a 3rd party can send the customer a gift. The JavaScript code worked on the Thank You page, but I need to have a few-day delay before the script runs, so I'm trying to do this with Zapier instead. But Zapier is giving the following error when the same code is used there:
The run javascript could not be sent to Code by Zapier. SyntaxError: Unexpected token <
Zapier Support could not help, and I couldn't find the solution in Zapier's documentation.
Can someone please help modify the short code below, so that it can be run by Zapier?
<script src="https://members.thirdparty.com/jsapi/fbDE_Voucher.min.js"></script>
<script>
window.onload = function(){
var fdDE_detail = {
"fbDE_sender":'12345-67890',
"fbDE_fullname":"'"+inputData.CustName+"'",
"fbDE_email":"'"+inputData.CustEmail+"'",
"fbDE_amount":inputData.VoucherValue,
"fbDE_business":54321,
"fbDE_message":'Thank you for your purchase!'
}
fbDEVoucher(fdDE_detail);
}
</script>
The variables CustName, CustEmail, and VoucherValue are from prior Zapier steps. The first 2 need to be within single quotes, and the third is an integer (not requiring quotes). Please see image below:
JavaScript code for Zapier
Does anyone know how to fix the above error (in bold) so this code runs?
Appreciate your help! Thanks.
Zapier's code runs in Node.js, which is a different environment than the browser-based JS your code was running in before.
First off, <script> tags aren't available, since that's HTML. Whatever code comes in through fbDE_Voucher.min.js will need to be loaded separately. If it's not too long, you can paste it into the code window (but there's a better solution, see below).
There's also no window global, but you don't need it anyway. So to get this close to working, it would be something like:
// doesn't work, fbDEVoucher is undefined
fbDEVoucher({
fbDE_sender: "12345-67890",
fbDE_fullname: inputData.CustName, // doesn't need to be re-wrapped in a string
fbDE_email: inputData.CustEmail,
fbDE_amount: inputData.VoucherValue,
fbDE_business: 54321,
fbDE_message: "Thank you for your purchase!",
});
That's all you would need, assuming your function is already defined.
The best option for you here is to create a custom Zapier integration. This gives you a more full-featured JS environment than a Code by Zapier step, plus dramatically more control. You can include the aforementioned file and call the function as needed. There's docs about that here: https://platform.zapier.com/

Opencart - cant change js files. adding kind of reddots at the end

firstly very sorry, I cant find out what the real problem is.
I ll try to explain.
My client given code which is developed using opencart and nitropack.
he includes common.js in header, it is basic js file with some ajax calls, UI events etc which has 1297 lines(no formating in code, lots of blank spaces, blank lines etc).
my real problem is, when I made any changes in this file,
the browser console is throwing error invalid or unexpected token.
I checked the common.js file in browser console, seeing that some kind of reddots added at last of the file. I just added a alert() at the begining of file. nothing else.
very sorry, dont know how to explain more detaily.
This is the first time I have seen this kind of issue.
when I removed the alert(), the error gone.

Get code of specific line in Javascript file

When catching an error, I want to get with the stack trace the actual code of the line that triggered the error.
Given that I have the path to the file and the line number throwing the error, what's the best way to also get the actual code of that line?
Beyond the obvious of "looking it up in the file", there are a few things you can do to get it automatically. Checkout the Tracekit project on GitHub. For errors it captures, it will do an AJAX request for the script and find the relevant lines in the text.
Alternatively, if you're looking for a way to handle this automatically, you should consider a service like TrackJS that will capture all the relevant scripts and apply sourcemaps for you. I am one of the original developers and I've used it on many projects to fix bugs ridiculously fast :)

Requiring a .js file in Windows

I'm just starting to pick up javascript and casperjs for a project that I'm doing. I'm trying to create a project that uses babyparse in it.
Currently I have babyparse.js located at C:\js\babyparse.js.
I'm having trouble including babyparse, and I've tried a couple different ways of doing it.
1) eval('C:\js\babyparse.js') - I come up with a syntax error "Invalid Character \u0008". I found this on StackOverflow, but I was unable to find the unicode character in babyparase.js.
2) require('C:\js\babyparse.js') - this just doesn't even find the right path in windows. I'm assuming that's because of the backslash pathing of windows as opposed to the regular unix forwardslash.
3) require('C:\\js\\babyparse.js') - this gets the correct path in windows, but I get the error that CasperJS couldn't find the module C:\js\babyparse.js
I feel like I've looked a lot through stackoverflow, but maybe I'm just missing something obvious. Thanks in advance for the help!
Currently I have babyparse.js located in C:\js\babyparse
require('C:\js\babyparse.js')
You've got the path wrong it seems. The correct path would be
require('C:\\js\\babyparse\\babyparse.js')
Beware that babyparse is a node.js module. It may use some of node.js native modules wich are not present in PhantomJS javascript interpreter in which case your script will break.
If you want to use csv parsing while scraping, it's definitely better to use PapaParse which is specifically designed as general-flavour javascript without dependencies, "not even jQuery".
I managed to solve the problem!
The following snippet worked for me:
var fs = require('fs');
eval(fs.read('papaparse.js'));

Socket.io failed to load websocket.js

I tried to use socket.io in an simple app.
When it is calling the following js file:
node_modules\socket.io\lib\transports\websocket.js
The following line failed to load (It didn't really fail. It actually returned some empty result and failed some later codes using protocolVersions):
var protocolVersions = require('./websocket');
I debugged a little bit and it seems that the intention of this line is to load the following js file:
node_modules\socket.io\lib\transports\websocket\index.js
However because there is also a "websocket.js" (the file being run) under the "transports" folder, the require functions always tries to load "websocket.js" instead, and return some unexpected results.
I changed the folder name to "websockets" and call "require('./websockets')" instead, and it fixed the problem. However this is a shared library I am not feeling comfortable messing up its codes.
I am trying to understand why this problem happened this way and what should be the best way to work around it. I am sure this piece of codes has been well tested before released.
You probably already noticed that I am using backslash '\' to separate the path. Yes I am running it on Windows! Will that create any difference?
Thanks!

Categories

Resources