0

So I have a PHP website and I am using a jquery AJAX event to access my database. The problem is when the results are returned I can briefly see the raw javascript code and then it is eventually rendered. Can anyone help by explaining to me why this happens and also how I can fix such a situation.

**************** Edit ***************************

Below is a snippet of where i am adding my javascript code. I do this just before the closing body tag.

    </div>  
    <script src="js/jquery-ui.min.js"></script><!--JQuery UI-->
    <script type="text/javascript" src="js/d3/d3.min.js"></script>
    <script type="text/javascript" src="js/c3/c3.min.js"></script>
    <script language="javascript" type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
    <script language="javascript" type="text/javascript" src="js/lib/bootstrap.js"></script>
    <script language="javascript" type="text/javascript" src="js/manageMarks.js"></script>
</body>

A snippet of my external file is as follows:

    $(document).ready(function(){
      $('#careerSearch').on('click', '.hsSubject', function(){
    var sbjCode = $(this).attr('data-subName');
    var user = $(this).attr('data-user');
    var path = $(this).attr('data-path');
    event.stopPropagation();

    if(sbjCode=='L.O' || sbjCode=='English FAL' || sbjCode=='Afrikaans FAL'){

    } else{
        $.ajax({
            type: 'POST',
            url: 'includes/highSchoolFiles/careerSearchFiles/suggestionsHandler.php',
            data:{sbjCode: sbjCode, user:user, path:path},
            success: function(data){
                $('.subSearchBody').html(data);
            }
        }).error(function(){
            alert('An Error Has Occured');
        });
    }
});
});
9
  • Please provide code. Commented Aug 4, 2015 at 20:27
  • Is the JS in the head of the document? Commented Aug 4, 2015 at 20:30
  • @Seano666 no its just before the footer Commented Aug 4, 2015 at 20:31
  • If you are using jQuery, jQuery's $(document).ready() (within either script tags within the head or in an external file referenced in the head) is preferable to putting your JavaScript code right before the footer. Commented Aug 4, 2015 at 20:37
  • one of the reason, may be <script></script> tag not closed properly, may b you missing > or /, provide code snippet. Commented Aug 4, 2015 at 20:38

1 Answer 1

3

Use jquery library link in head section.

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

2 Comments

my jquery library is not in the head, its just before the closing body tag.
usually when you use CDN links in the end of document its load when all the documents is loaded and more over its download from online. that's why your code shows as jquery is not there but it comes back when jquery is loaded. to avoid this u either can use library in head section or put your code in between<script> <!-- code //--> </script> like this.

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.