0

I have created jquery functions and put them in a js file and called the file from my php using <script src="newajax.js"></script>. This was working and now it has stopped working. If i copy all my functions into the php file between the <script></script> tags, It works. I know there is not any issue with the js script.

To test I only added

$(document).ready(function(){ 
  alert("ready");
});

into the js file and called it from my php. It did not show the alert but when I did this inside the php file

<script>
    $(document).ready(function(){ 
       alert("ready");
    })    
</script>

It worked.

So I know there isn't any issue in the php file. It just looks like the script is not being picked up and it was before with exactly the same code. I have not removed the files to a different location. The js files are in the same directory as the php file.

Anybody encountered such an issue? Or know a reason why this could happen. FYI - I know they are html tags but I have used php extension to be able to run php functions in my file. The jquery.js file is loaded first before my js file.

When I loaded the webpage in a new tab, it worked. I was refreshing the same browser window when the .js script stopped being called.

Amar
  • 17
  • 3
  • 10
  • have you check your browser console ?it shows any error ? – Manthan Dave Dec 01 '16 at 05:24
  • care to share your JS file code? It surely has a js error that will show in console if you keep console open while loading website – shivgre Dec 01 '16 at 05:26
  • can you share your directory structure? – Suhindra Dec 01 '16 at 05:27
  • make sure its not conflicting .. check error console while you are adding in your js file .. – Mittul At TechnoBrave Dec 01 '16 at 05:28
  • if you have already **document.ready** in your js file file, then put that function only which you want to do .. additionally, in firebug check whether you are getting any 404 related to this file. – Mittul At TechnoBrave Dec 01 '16 at 05:29
  • also you need to make sure that, your **jquery.js** file should be loaded first and then after your **** should be loaded.. so also take care of that – Mittul At TechnoBrave Dec 01 '16 at 05:30
  • checkout this http://stackoverflow.com/questions/1857072/why-is-document-ready-not-firing-for-me – MasoodRehman Dec 01 '16 at 05:31
  • Check the network tab of inspect element is jquery library is actually loading ? – MasoodRehman Dec 01 '16 at 05:33
  • It's actually working now. I tested with different alert messages and it works. Very strange. @shivgre like i mentioned I copied the code between the script tags and it worked just not via the file. – Amar Dec 01 '16 at 05:40
  • Make sure `` is placed after the jquery library loading script tag. – josephting Dec 01 '16 at 05:49
  • Make sure your jquery.js file should be loaded first then your newajax.js should be loaded or else it will give throw you an error. Care to share your Js file? – Jaymin Dec 01 '16 at 05:49
  • Ok, so it stopped loading again. Basically I am just reloading the same browser every time. When I opened a new browser window and entered the url it worked. Is there a reason why this is happening? – Amar Dec 01 '16 at 05:52
  • @JayminsFakeAccount The issue is nothing to do with the content of the js file, it's that sometimes it does not pick up the js file from the php file. If I was making an error in the js file or if the question was code related then yes surely I would share the script but it's working and by looking into the content of the file would drag the post off topic. – Amar Dec 01 '16 at 06:04
  • have you included jquery in your php file? – abhit Dec 01 '16 at 06:20
  • make sure you have placed `newajax.js` in the correct path. you are using a relative reference path. Check the error report in browser console. And check the network tab in your browser console. – Fu Xu Dec 01 '16 at 06:46

0 Answers0