2

So basically I have this code where I click on the image, it gets html file and should display it on the same page. It does display it but on another page, my guess is that it's not actually loading js file for some reason. Anyone can help?

View:

@extends('layouts.master')

@section('title', 'Best programmer ever')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="{{asset('/js/template.js')}}" rel="javascript" type="text/javascript"></script>
@section('content')
@endsection
        @section('template')
        <!--     @foreach ($templates as $template)
           {{$template->image}}
            {{$template->file}}
        @endforeach
        -->
        <div class= "template_class">
          <a class="content-link" href="templates/template1.html"> 
        <img id = "image" src="{{ asset($template->image )}}"/>
  </a>
</div>
        @show

JavaScript:

$(function(){
   $('.content-link').click(function(e){
       e.preventDefault();
       $('.content').load(this.href)
                    .fail(function()( alert('Oops...something went wrong')));

   });
});
alert("hello");

It doesn't even show alert so that's why I think it is not loading it.

1
  • Does your js file shows up in the network tab of chrome tools? Commented Oct 12, 2016 at 16:32

1 Answer 1

1

The <script> tags are out of the @section sections.

Try changing it like this:

@section('content')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="{{asset('/js/template.js')}}" rel="javascript" type="text/javascript"></script>
@endsection

If it doesn't work, check if the JS files are really included in your browser. (Open the Chrome Dev Tools and check the DOM)

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

3 Comments

seems like it's working however I am getting: template.js:5 Uncaught TypeError: $(...).load(...).fail is not a function
Seems like it's a jQuery error. I don't think that you can use the fail() method after load(). $.load Doc
however if I remove fail() it doesn't work at all, with it at least it displays the page but unfortunately on another page and I want it on the same one

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.