0

I have a very odd problem where the javascript is executing fine however it also displays the script as text.

The script is within a PHP file that I load with AJAX.

<div id='main_container'>

</div>
<br>

<div style='border-top:1px solid grey;padding-top:10px;padding-bottom:10px;position:absolute;bottom:0;width:100%;'>
    <a style='padding-left:10px;padding-right:15px;width:50%;border-right:1px solid #0cf;' onclick='editFav();' href='#'>Edit Favourites</a>
    <a style='padding-left:10px;width:50%;text-align:right;' href='#'>Add Favourite</a>
</div>



<script type='text/javascript'>

$('#main_container').load('ajax/favourites/list.php', {});

</script>

The code works fine and the script executes, however it still displays itself..

EDIT - I was able to fix the problem by just adding something after it. I addded "<p></p>" and it was fine after that.

1
  • Try <script type="text/javascript"> instead of <script type='text/javascript'> Commented Aug 30, 2014 at 23:14

2 Answers 2

0

Try this and see what error you get or does it show up the content of list.php

<script type='text/javascript'>
$( "#main_container" ).load( "/ajax/favourites/list.php", function( response, status, xhr ) {
  if ( status == "error" ) {
    var msg = "Sorry but there was an error: ";
    $( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
  }
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

I made two small files:

file 1: test.html

<!DOCTYPE HTML>
<html>
 <body>
   <div id='main_container'></div>
   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script>
     $('#main_container').load('try.html', {});
   </script>
 </body>
</html>

file 2:

<!DOCTYPE HTML>
<html>
  <body>
    <script type='text/javascript'>
      document.write('this is a test.');
    </script>
  </body>
</html>

And they don't show the Javascript. If you still have the problem try to see if you can reproduce it with these two files. Try to make them more similar to yours in small steps, and see where it goes wrong.

Comments

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.