Problems installing Dajaxice properly - javascript

I have dajaxice installed on my python2.6 dist-packages folder, that seems to work alright with importing the stuff. But it throws all kinds of errors, since the django template tags are not being rendered.
invalid property id [Break on this
error] {% for module in
dajaxice_js_functions %}\n
Makes sense, so I tried putting the js into HTML straight, which solves some of the problems of the templatetags, but gets messed up again, probably since its looking for dajaxice_core_loop.js
invalid property id
[Break on this error] ,\n
I kept on uncommenting JS that throws me errors, but here i stripped it down to an extent that it is not working at all (duh). Because when I recreate the example with the button and hit the button i get:
Dajaxice.MYAPP is undefined
of course, MYAPP is my specific application that holds the ajax.py
I guess I am doing it all wrong, but I can't really tell from the documentation what that might be specifically.

Found that I shoulnd't have configured that Nginx serves my js statically, resolved!

Quick note: on the Django development server I had to place the Dajaxice URL entry before the static media so it could parse the javascript correctly.

Related

JavaScript failed to load resource: file not found, but the file is a Laravel auto-generated view

This is a problem that I just now encountered. When I go to certain pages within my application, I see an error in the dev console that says:
inject.preload.js:373 GET blob:http://my-app-name.test/ba65127c-383e-45b7-8159-9b52ea288658 0 ()
So, when I go to inject.preloader.js, and I find the line that is throwing the error, it says Failed to load resource: net::ERR_FILE_NOT_FOUND.
That's fine. I know how to normally fix that error. But since I'm working with laravel for the first time, I believe that the file it's talking about is one of the files Laravel automatically generates in App/storage/frameworks/views/. And if that's the case, how do I fix this error?
The error doesn't actually impact anything. The pages it appears on are all functioning normally as far as I can tell, and there don't seem to be any issues in the blade files.
I was just curious if anyone else had encountered an issue like this before. I haven't changed my blade template used for the headers and scripts, and the only thing I changed in the page that is throwing the error is adding a bootstrap 4 modal.
I can link to a github repo if needed.
I don't know why this fixed it, but I moved my javascripts includes in the master.blade.php template, and it's not a problem anymore.

jQuery doesn't work properly after major renaming

I'm using jQuery 2.2.4. Everything was ok until I done a major renaming. I renamed the main object, from actual application name to "app". I also renamed other things, as I was changing my app name.
Unfortunately jQuery (minified) doesn't work properly now . I noticed it 2 days after. I spotted 2 weird errors. For example:
$('body').on('change','input:not(.error)', function() { });
When input is changed I get an error "cannot read property test of undefined". jQuery was concatenated with my application file. When I moved jQuery to a separate file I got "uncaught reference error: app is not defined" for that event.
I renamed my main object back from app to something specific, but it didn't have any effect. And development version of jQuery works fine. I can't run a diff, because I changed so many things. Either I will find what causes the issue, or I will have to revert and do everything again.
Does anyone know what might cause jQuery to break? I remind that it only doesn't work on the minified, development version of jQuery.

Error in Rails with JS code

Rails will not let me run JS code, I have these errors
1)
2)
whenever you add JS code, the errors appear.
Some idea why this happening?
Just because you're getting error highlights in your IDE, doesn't necessarily mean your code is wrong. Try running your server, navigate to your site from your browser, and check the developer console. Do you still see javascript errors?
This warning (it is not an error) is being displayed because your IDE thinks that the variable $ is not defined in your code. However, it is not able to find out that $ is a global variable defined in the jQuery library, imported a few lines before.
The IDE is just saying that the presence of that variable is not guaranteed unless you properly import the needed libraries to make it exist (jQuery in this case). Your code should work properly. In order to identify errors in your javascript code, I would recommend you to use the built in console in the web browser.

Bundling and minification - when enabled scripts don't work

Trying to apply bundling to scripts, which worked fine when were located at pages in old way (manually).
This is bundles registration:
Bundle sbundle = new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/menu-correction.js",
"~/Scripts/validation-rules.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery.validate*");
bundles.Add(sbundle);
bundles.Add(new ScriptBundle("~/bundles/session").Include(
"~/Scripts/jquery.plugin.js",
"~/Scripts/jquery.countdown.js",
"~/Scripts/session-management.js"));
//others
Then in Layout page call:
#Scripts.Render("~/bundles/jqueryval")
#Scripts.Render("~/bundles/session")
But when minification is become enabled, i got this errors in chrome console:
Uncaught SyntaxError: Unexpected identifier jqueryval:1
Uncaught SyntaxError: Unexpected identifier session:1
Also i can see my scripts in tab page "Sources" of chrome developer tools - they are minificated successfully. Spent enough time trying to fix this. What can be a reason of this mistake?
Thanks in advance.
I provided insufficient information: there is some logic in Application_PostRequestHandlerExecute method which wrotes some tags directly to response stream (is needed for js). I noticed that tags which were written directly in response stream with bundling is being written actually in the end of minificated js file.Thus, syntax is broken and js file doesn't work (Without bundling my approach works fine).
Solution: transferred my logic from Application_PostRequestHandlerExecute to Application_AuthorizeRequest method, where it should was located initially.
UPDATE
Well, tag generating logic was entirely removed from Application_PostRequestHandlerExecute method, cause only now i understand that this is absolutely wrong idea.

Symfony 2 - Assetic JavaScript compression causing errors

I'm trying to put a Symfony 2 app in production mode. It all runs fine except for the fact that the compressed single JavaScript file causes errors and makes the site unable to render correctly. I found this through the debug console on the browser:
Uncaught TypeError: undefined is not a function
Uncaught TypeError: Object [object Object] has no method 'treeview'
The first error refers to jQuery plug-ins
The treeview refers to a plugin for jQuery which renders a tree like directory structure.
On the other hand, it all runs fine on dev mode cause it doesn't do the compression and it just includes every file one by one. Can someone help me on this one?
I've found a solution to this, it appears the issue is related to missing semi-colons.
When something is the last statement in a js file a semi-colon isn't required however assetic just joins the files together and only adds a new line.
Check the file which is being included just before the broken plugin javascript and make sure it ends with a semicolon.

Categories