Hello, I am working with JQuery and I am having issues with it. I do not get any error messags but it just doesn’t work. I worked with it locally (same files/same locations) but when usinng the website I found that it does not work. I have tried many different ways of incorperating JQuery but none have worked. I have all files in the same folder. Any help would be appriciated.
Hmm chatbox, we don’t allow chat scripts to be hosted here so it’s possible that system blocks chatbox.php and returns 403.
You didn’t close the script
tag after declaring jQuery.
<script src="jquery.js"></script>
<script>
setInterval(function() {
$("chatbox").load("chatbox.php");
}, 500);
</script>
it isn’t a chat script, its code that I wrote that pulls from a database and prints out what is inside.
I do have it closed, I just have some code under it that I didn’t bother putting in the screenshot.
You didn’t get me:
because it contains the word ‘chat’,, rename it to something else.
@alexvf it is actually correct, just the picture doesn’t show a part of it.
I have a file named “chat_input.php” but that one works fine. Is there a specific reason this one is not?
I’m talking about the first line of code in your screenshot. Not the last.
You have to close the script tag where you call jQuery and open another one for the internal js.
<script src="jquery.js"></script>
<script>
...
</script>
I tried it both ways and neither would work
that did not work, I renamed it to just “box.php” and I still have the same issue.
It would be easier to debug if you gave us your domain name.
Open your browser’s developer tools, and check for errors in the tab “Network”.
Question, can you have comments/chat support (for like tech support, but not like a chat site)?
Oh, wait… nvm…
PHP sucks with websockets anyways (almost no support for it), so it wouldn’t be ideal even if it was allowed.
Try debugging whether or not jQuery is loaded. Is the jQuery file hosted on your website? You seem to have it hosted locally.
If not then replace src="jquery.js"
to src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"
.
I have tried doing it both ways, neither worked unfortunately.
What do you mean “it worked”?
Did you check that jQuery is loaded?
Try opening the console and seeing if jQuery functions are there…
Don’t forget the “#”, jQuery’s selection is like JavaScript’s document.querySelector
Like @alexvf suggested, I would look in the Network tab too.
But that’s primarily to look for whether the XHR request was fired at all. Whether it fired, and what was returned, can give quite an important clue too.
If jQuery really didn’t work, you’d probably get an error like $ is not defined
or something like that.