Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15676 > unrolled thread

Problem with jQuery in Laravel

Started byJohn Dawson <jayrdi@gmail.com>
First post2015-09-13 03:25 -0700
Last post2015-09-14 02:57 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  Problem with jQuery in Laravel John Dawson <jayrdi@gmail.com> - 2015-09-13 03:25 -0700
    Re: Problem with jQuery in Laravel Jerry Stuckle <jstucklex@attglobal.net> - 2015-09-13 09:59 -0400
    Re: Problem with jQuery in Laravel Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-14 00:09 +0000
    Re: Problem with jQuery in Laravel John Dawson <jayrdi@gmail.com> - 2015-09-14 02:57 -0700

#15676 — Problem with jQuery in Laravel

FromJohn Dawson <jayrdi@gmail.com>
Date2015-09-13 03:25 -0700
SubjectProblem with jQuery in Laravel
Message-ID<64874b9b-55cf-4352-b448-9c790725b8a0@googlegroups.com>
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

[toc] | [next] | [standalone]


#15677

FromJerry Stuckle <jstucklex@attglobal.net>
Date2015-09-13 09:59 -0400
Message-ID<mt3vd1$c5h$1@dont-email.me>
In reply to#15676
On 9/13/2015 6:25 AM, 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.
> 
> 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
> 

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
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#15678

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-09-14 00:09 +0000
Message-ID<mt537f$ji9$4@dont-email.me>
In reply to#15676
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, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#15679

FromJohn Dawson <jayrdi@gmail.com>
Date2015-09-14 02:57 -0700
Message-ID<59b17c19-7a5c-4d23-b19b-18f60a48f3df@googlegroups.com>
In reply to#15676
On Sunday, September 13, 2015 at 11:25:28 AM UTC+1, 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.
> 
> 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

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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web