[Flask] Flask issues with JSon queries and environment variable "flask-app" problem..

mhysnm1964 at gmail.com mhysnm1964 at gmail.com
Sun Sep 15 19:11:33 EDT 2019


Dennis,

Thanks, refer to my new email which is the environment I am running. I will
look into your email in more depth.

-----Original Message-----
From: Flask <flask-bounces+mhysnm1964=gmail.com at python.org> On Behalf Of
Dennis Lee Bieber
Sent: Monday, 16 September 2019 5:10 AM
To: flask at python.org
Subject: Re: [Flask] Flask issues with JSon queries and environment variable
"flask-app" problem..

On Sun, 15 Sep 2019 11:40:53 +1000,
<mhysnm1964 at gmail.com> declaimed the
following:


>
>Examples I have seen have the script in the HTML code and they are 
>using ginger and flask functions to provide the URL to the JavaScript. 
>I have done this as well with the same errors seen in the chrome debug 
>output. I have used an absolute and relative paths with the same 
>failure. This has been done in the JavaScript file or within the HTML 
>code. Below is the error
>messages:
>
> 
>
>error messages from Firefox console:
>
>WarningThe script from "http://localhost:5000/static/test_json.js" was 
>loaded even though its MIME type ("text/plain") is not a valid 
>JavaScript MIME type.
>
>localhost:5000 ErrorSyntaxError: missing { before function body
>test_json.js:31:57
>

	The first warning indicates the server is returning the file with a
"text/plain" -- you may have to check the Flask configuration for static
files to ensure the correct header is used.

	Are you using the Flask development server/route or are you going
through something like nginx where nginx is serving the static files
directly? That will affect where you have to check for MIME type settings.

	For the second message -- have you examined line 31 of your file?

	Cut&Paste into Visual Studio Code shows this for line 31:

    request.onreadystatechange = function () {

(which, is only 47 characters long but your message identifies 57; do you
have mixed tabs and spaces that got compressed when posting?)


>
>I do not know if this is an JavaScript error or python. I have even 
>used known working JavaScript examples with the same result. Below is 
>the current version of the code.
>
> 
>
>JavaScript code for test_json:
>
>/* standard Ajax xhr function */
>
>function getHTTPObject() {
>
>    var xhr;
>
>    if (window.XMLHttpRequest) { // check for support
>
>        // if it's supported, use it because it's better
>
>        xhr = new XMLHttpRequest();
>
>    } else if (window.ActiveXObject) { // check for the IE 6 Ajax
>
>        // save it to the xhr variable
>
>        xhr = new ActiveXObject("Msxml2.XMLHTTP");
>
>    } // end if
>
>    return xhr;
>
>}
>
>function ajaxCall(dataUrl, callback) {
>
>    /* use our function to get the correct Ajax object based on support 
> */
>
>    var request = getHTTPObject();
>
>    request.onreadystatechange = function () {
>
>        if (this.readyState == 4 && this.status === 200) {
>
>            // save the ajax response to a variable
>
>            var tableData  = JSON.parse(request.responseText);
>
>            // make sure the callback is indeed a function before 
>executing it
>
>            if (typeof callback === "function") {
>
>                callback(tableData);
>
>            } // end check for function
>
>        } // end ajax check
>
>    } // end state check function
>
>    request.open("GET", dataURl, true);
>
>    request.send();
>
>} // end function for loading ajax data
>
>ajaxCall ("/transactions_summary_report", function(data)) {
>
>    console.log(data);
>
>    };
>

	I'm not a JS person but that looks rather odd to me...

	That looks like an invocation of "ajaxCall", passing a string, and
whatever "data" is after I'm guessing a type coercion to function. I don't
know where "data" is coming from. However, IF that IS an invocation, what is
the { console.log(data); }; supposed to be?

	Are you trying to pass an anonymous function? Maybe you want

ajaxCall ("/transactions_summary_report", function (data) {

    console.log(data);

    }; );

to make the stuff inside {} the body of the anonymous function.


	AH! there is a help... If I remove all the blank lines from your
source (it would help, in the future, if you adjust your posting client to
NOT double space when you paste code...

-=-=-=-
/* standard Ajax xhr function */
function getHTTPObject() {
    var xhr;
    if (window.XMLHttpRequest) { // check for support
        // if it's supported, use it because it's better
        xhr = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // check for the IE 6 Ajax
        // save it to the xhr variable
        xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } // end if 
    return xhr;
}
function ajaxCall(dataUrl, callback) {
    /* use our function to get the correct Ajax object based on support */
    var request = getHTTPObject();
    request.onreadystatechange = function () {
        if (this.readyState == 4 && this.status === 200) {
            // save the ajax response to a variable
            var tableData  = JSON.parse(request.responseText);
            // make sure the callback is indeed a function before executing
it
            if (typeof callback === "function") {
                callback(tableData);
            } // end check for function 
        } // end ajax check
    } // end state check function 
    request.open("GET", dataURl, true);
    request.send();
} // end function for loading ajax data ajaxCall
("/transactions_summary_report", function(data)) {
    console.log(data);
    };
-=-=-=-

Makes the line

ajaxCall(...

#29, and column 57 is the second ")". And yes, that fits the error message
in that the ")" is being seen as what would be the body of the function
definition which is lacking the "{" to start it.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

_______________________________________________
Flask mailing list
Flask at python.org
https://mail.python.org/mailman/listinfo/flask



More information about the Flask mailing list