Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with jQuery in Laravel

19 views
Skip to first unread message

John Dawson

unread,
Sep 13, 2015, 6:25:28 AM9/13/15
to
Hello everyone, I'm new to the group and am hoping that someone may be able to help me with a problem I'm having with a web application I've created.

The web app takes input from a user, queries an API, processes the data with PHP and then presents it as a series of graphs using jQuery and D3. I initially set this up in a procedural manner but have since been implementing it using the Laravel framework. The problem I am having is that the JavaScript is not working properly in the final page; I think it has something to do with the way the Blade template system works.


I know that it is accessing the JavaScript file correctly as it loads up the initial graphs. However there is some extra functionality to reload the graphs according to different time spans and also to scroll through the data in the graphs. After it has loaded the page, none of the jQuery stuff is working.

I don't want to paste a load of unnecessary code here but here is a link to the question I have asked on Stack Overflow:


http://stackoverflow.com/questions/32454521/jquery-not-working-properly-in-laravel-5


I don't know where the problem lies which is why I have placed so much code in that question, but that's probably why it's had no answers!

** ADDITIONAL 1 **

I changed the javascript.php file created when publishing PHP-Vars-To-Js-Tranformer to this:

return [
'bind_js_vars_to_this_view' => 'pages.data',

'js_namespace' => 'Graphs'
];

In graphs.js I am then getting the data using that namespace via e.g. Graphs.allCited. I can call the data in the console so I'm guessing the namespace may be correct but maybe there is a problem with how I've set up the bind_js_vars_to_this_view variable. pages.data refers to the view that displays all the graphs, as per the previous screen dump. It's stored as resources\views\pages\data.blade.php.

In routes.php I refer to the route as Route::post('data', 'PagesController@process'); and then, at the end of process, I call return View::make('pages.data');
** ADDITIONAL 2 **
After some troubleshooting, it seems that the problem is with the way I've implemented the PHP-Vars-To-JS-Transformer. The console recognises all the data that I have passed through via the PagesController like Graphs.allCited or Graphs.userFunded, but doesn't recognise any of the variables created in graphs.js dynamically. That is, it must recognise them when it first loads the page as it uses e.g. palette1 to colour the bar graph for the first graph, but after the page has loaded, palette1 comes up as undefined in the console.

I'm not sure why this is though - has anyone used PHP-Vars-To-JS-Transformer before and can spot what I'm doing wrong?


Thank you in advance for any help; I'm really stuck with this!

John

Jerry Stuckle

unread,
Sep 13, 2015, 10:00:01 AM9/13/15
to
The transformer looks to be part of the laravel package, one that I
doubt anyone here has ever used. You should be asking questions about
it from the developers of the package. They know their code better than
anyone else.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

Denis McMahon

unread,
Sep 13, 2015, 8:11:22 PM9/13/15
to
On Sun, 13 Sep 2015 03:25:10 -0700, John Dawson wrote:

> Hello everyone, I'm new to the group and am hoping that someone may be
> able to help me with a problem I'm having with a web application I've
> created.

Can you check whether (a) the data you're sending to php is actually what
you think it is, and (b) whether the output generated by php in response
to that data is what you expect it to be?

If the answer is yes, yes, then your php code is executing fine and your
problem lies elsewhere, and outside the scope of this newsgroup.

If the answer is no, *, then your php is not processing the data you
think, and you need to fix the input data first.

If the answer is yes, no, then your php is not processing the data as you
expect, and that we can probably help you with.

If the answer is you can't actually check, then you're unable to provide
us with sufficient information to offer you any meaningful help. Perhaps
you would be better off asking the question:

I have a piece of php code that takes an http request and generates a
response. What tools and troubleshooting methods would you suggest are
best for checking that the input from the http request and the output in
the response are as expected?

--
Denis McMahon, denismf...@gmail.com

John Dawson

unread,
Sep 14, 2015, 5:57:16 AM9/14/15
to
Yes, the data is as expected in the final page when I echo it. I think the problem lies with the way the Laravel framework Blade templating system loads script links. I have had some feedback on Stack Overflow and this seems to be the issue. I guess it's specifically a Laravel question. Thanks for your help.
0 new messages