XML Parsing Error when getting query from perl script - javascript

I am new to Perl and I just copied the Cleb answer (https://stackoverflow.com/a/28992992/5553963) (and also made the ajax.pl executable) but it doesn't work and it gives this error:
XML Parsing Error: not well-formed
Location: file:///home/workspace/snmp-agent/query_ui/ajax.pl
Line Number 1, Column 2:
When I run the ajax.pl there is no error but when I get the query via Ajax I faced above error and as you can see from Cleb answer the first line is: "#!/usr/bin/perl".
Can someone please give me a hint how to solve this?

CGI programs need to be executed by a web server (which has to be properly configured to execute CGI programs).
You are opening the file directly in a browser from the filesystem (we can tell because the Location is a file: scheme URL) and it is trying to parse it as XML (possibly you have associated pl files with the XML mime type in your OS somehow). Since it isn't XML, it fails.
Pick a web server, install it, and consult its manual on how to configure it to run CGI programs.

Related

Photoshop 8800 Error only after python creates the file

I have a bit of a weird situation that I will try to explain the best I can.
I am using Python to launch photoshop and run a javascript file. But my goal is for python to generate the javascript first, then run it in photoshop.
In order to do that I have python copying the javascript file, then replacing a single line of code and running this new copy.
When I run the original javascript file it works as intended with no problems.
When I run the copied javascript file it works as intended with no problems.
When I run the copied javascript file that has the line replaced, it gives me an 8800 error.
At this point, even if I manually type the replaced line to match the original javascript file. I will still get an 8800 error.
Does python somehow write files differently?
Here is the code I am using to replace the copy and replace the javascript contents:
from shutil import copyfile
jsx_file = r'E:\PS\_javascript_constructor_template.jsx'
jsx_file_new = r'E:\PS\_javascript_constructor_template_new.jsx'
copyfile(jsx_file, jsx_file_new)
with open(jsx_file_new, "r") as fin:
data = fin.read()
with open(jsx_file_new, "w") as fout:
fout.write(data.replace("!REPLACEME!",'"E:\PS\MockVar.csv"'))
Any ideas?
SIDE NOTE: I am only doing this because I have no idea how to pass an argument from python into the javascript file I am subprocess calling.
I would much rather send an argument to the javascript file than build new files enitrely.
If you'd rather send an argument to the Photoshop script, I'd recommend using interprocess communication. You can use the socket module in Python and the Socket object in Extendscript to send messages back and forth. Check out External Communications Tools in the Adobe Tools Guide for more information.

Uncaught SyntaxError: Unexpected token < on each js file that invoked in the index html

I am using mean stack to build a website, when testing, chrome returns the error like:
Uncaught SyntaxError: Unexpected token < angular.js:1.
I don't know what's wrong and what should i do.
Here is the directory of my app:
E-study
-client
-app
-components
-all the libraries are here.
-index.html
-controllers.js
-node_modules
-server
-config
-server.js
And I run the server in E-study like :node server/config/server.js
The scripts in the index.html is<script src="client/components/angular/angular.js"></script>
Just don't know why all the js files are changed to index.html when open in the browser.
open up those library files and see if there are some extra symbol < probably you will find it in the beginning.. if still not able to fix... simply download the fresh library (if those are libraries) from the internet and try again.
make sure that you don't put <script> </script> tags in the included .js files. that is an incorrect syntax for script files.
also make sure you are providing the correct path??? providing incorrect path can return a builtin customized error page. which is html. may be that is the source of error because returned page is HTML which is most likely going to start with a < symbol. and offcourse not a js file.
to ensure that the incorrect path is the issue just copy the path you included in the code and and paste into your favorite browsers url bar and hit enter. if you are not getting the script in plain text.. then it means you are not providing the correct path.
and if it is return a customized error page like .. 404 not found then probably it is returning the html and this is where the error is coming from.
In external js files, which you refer in some other files, don't use <script>..</script> tag.
For express server try to set the static path to entire project folder.It worked for me
app.use(express.static(__dirname ));
Could be a ReCaptcha bot checker type thing intercepting requests for JS files and serving up an HTML page instead, which is invalid HTML so it throws the < is invalid message error.
I know siteground specifically has issues with this intercepting CDN routed traffic.
Check with the host to remove this issue, in this case it's their anti-bot security setup. This has remedied these issues with Siteground for me.

How to use PowerShell output in JavaScript

I would like my JavaScript to use the PowerShell output, which is in JSON format, so I can draw a Google data table.
I have tried using window.clipboardData.getData('Text') but it doesn't seem like the answer I'm looking for and for some reason setTimeout() isn't working anymore. I have also tried event.dataTransfer.getData('Text') but I received an error
SCRIPT5007: Unable to get property 'getData' of undefined or null reference.
I kind of don't like having to copy to the clipboard because PowerShell does not take the same amount of time to finish executing every time. Additionally, the Google portion of the code constantly responds with error Invalid JSON string even though when I manually pasted the code, the data table loaded perfectly. I'm running on IE11.
You can install a HTTP server (like Apache or Lighttpd) on your computer and dump your JSON output in a .json file in the HTTP server directory.
Then you can make an ajax HTTP request to retrieved the file everytime you need it.

SAXON Error- How to ignore/skip it?

Using Saxon HE (net version) wget and batch, I'm trying to transform a page I've downloaded via wget.
Whenever calling the command on the page, I get the following error:
SXXP0003: Error reported by XML parser: The entity name must
immediately follow the '&' in the entity reference.
It is related to a line in a VERY awkward line of javescript. However, I have no control about the page I am wanting to transform, so I can't do anything against this error on that side.
Is there any way to tell Saxon to skip such errors? I would not mind if it would drop the entire tag, since I'm not looking to read any data from the javascript elements.
Big thanks in advance!
As the error message says, it is an error reported by the underlying XML parser that Saxon uses to parse the markup of the document you are providing to it. If that is not well-formed XML then any XML parser will reject it. Saxon offers you the choice to use an HTML tag soup parser like TagSoup instead by calling it with the option -x:org.ccil.cowan.tagsoup.Parser if you put TagSoup from http://home.ccil.org/~cowan/tagsoup/ on the class path.

Xml to js code problem

So i'm very new to xml to javascript so i thought I would learn from w3schools, but this site
http://www.w3schools.com/xml/xml_to_html.asp shows an example that I can't mimic locally. I copy/pasted the .js and downloaded the xml but I just get a blank screen!
It's working in there try it yourself but not for me? Do I need it on a server or something?
Yes, that code retrieves the XML data from a web server using AJAX. Since you don't have a server running locally, you can change the URL to point directly to the w3school's version:
xmlhttp.open("GET","http://www.w3schools.com/xml/cd_catalog.xml",false);
Alternatively, play around on their online version ;)
well i guess you have to add the example xml (cd_catalog.xml) to your file system. and you definitively have to access the html file on a server (apache i.e.)
First, ensure that both HTML file (with the Javascript block in it) and XML file are placed in the same directory.
Next, you probably need to place those files under your local web-server and open the HTML like this:
http://[local server host]/ajax.html
instead of opening the file directly from e.g. Windows Explorer:
C:\[path to the file]\ajax.html
For the latter case you'll get an "Access is denied" error.
-- Pavel
Are you running this under a web server or just creating a couple of text files and loading them in your browser?
The "GET" request this relies upon could possibly be failing.
Use Apache or another similar HTTP server and run the example as if it were hosted on the web.

Categories

Resources