1

First I want to tell you, how my project is structured basically. I have my views and my controllers. Then in public>JS folder I have jQuery placed as well as a plugin called sweealert.

Now I did this, so I'm sending an ajax request to a controller, which then returns data (abouot categories).

Now I have a problem. I have 2 different views, the one has the route /addProduct, there, everything works fine. The other route is for editing products, so those routes are for example /editProduct/1 for the product with the id one. On that view, using that described ajax doesn't work. Neither the subcategories are switched, nor anything else with jQuery works. The console, tells me why:

https://localhost/editProduct/js/jquery-3.1.1.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
https://localhost/editProduct/js/sweetalert.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
1:4 Uncaught ReferenceError: $ is not defined(…)

So jQuery and the sweetAlert plugin are looked up in the wrong folder, so jQuery is not working, thats why my AJAX success callback isn't working any more as well... Now the question is, WHY? Paths like addProduct work, but paths with something behind (like editProduct/1) doesn't work? And no, there are no typos or anything that could cause the problem, I tried to hardcode the id of the product to edit in the code, so I can call /editProduct and that worked, so it's that id that is added additionally.

Where does this problem come from (why does it search for js files in the wrong directory) and how can I solve it?

1
  • @RoryMcCrossan The https is correct, I have SSL simulated... But it should be localhost/js/jquery.....js and not localhost/editProduct/js/jquery....js Commented Nov 9, 2016 at 14:00

2 Answers 2

3

You're loading your scripts wrong. Use

<script src="{{ asset('js/jquery-3.1.1.min.js') }}"></script>

to make always sure your scripts are loaded correctly, no matter what url you're on.

See also: https://laravel.com/docs/5.3/helpers#method-asset

And https://laravel.com/docs/5.3/helpers for more awesome helper functions.

Sign up to request clarification or add additional context in comments.

Comments

1

need write url to your scripts like '/js/jquery-3.1.1.min.js'

1 Comment

omg, that works... Before (when including the scripts) I had ./js/jquery-3.1.1.min.js, so the relative part... That easy^^ thank you..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.