Java Script JQuery Won,t Work!

Fait

Seasoned Veteran
Joined
Oct 15, 2010
Messages
4,407
Reaction score
561
FP$
2,054
Hey I am trying to get jquery to work but for some reason it won,t run or excute anything todo with JQuery, Ive even tried A public server.

Heres the general.js coden

Code:
$(document).ready(function() { 

$('#content').load('content/index.php');

}};

Heres the html
Code:
<!doctype html>
<html> 

<head> 
<title>My Refresh Auto</title>

<link rel="stylesheet" href="css/styles.css" />

</head>

<body> 

<ul id="nav">
         <li><a href="index"> Home</a> </li>

         <li><a href="about">About Us </a></li> 

      <li><a href="contact"> Contact </a></li> 
</ul>
<div id="content"></div>

<script src=" http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="js/general.js"></script>

</body>
</html>

Am I doing everything right?
 
It looks fine to me, although I'm not sure about the link to index.php. I don't know what your directory structure looks like, but it looks like the only thing that could be wrong.
 
Ok JQuery is functional now

I have

Got Data Streaming Real Time
Prevented Default Enter etc

Now For some reason java script gets the PHP session veriable but carn,t get any post veriables.

Heres the java script(I want this script to load a PHP page which will insert the username and what the user typed into the sql database)
Code:
<textarea type="text" name="post" id="post" onkeydown= "
 if(event.keyCode == 13 || event.which == 13){
 event.preventDefault();
 
$('#content').load('ajax/chat.php');



$(this).val('');

;}"></textarea>
 
Is this for vanilla? i get that error with vanilla. :/
 
Instead of $ sign use "jQuery"

Also at the top of the file write "jQuery.noConflict();"

It should work now.
 
LiquidServe said:
Instead of $ sign use "jQuery"

Also at the top of the file write "jQuery.noConflict();"

It should work now.

jQuery.noConflict() will be useful if there is a conflict with other javascript libraries. But in his case the only library he use is jQuery. So that code won't make a difference.

@Spudster:
Instead of calling a PHP file directly, why don't you use ajax, instead?

Here is a simple ajax call example.

HTML:
Code:
<input type="text" id="username" />
<input type="context" id="context" />

jQuery:
Code:
var user = $("#username").val();
var content = $("#content").val();

$.ajax({
    url: "insert.php",
    dataType: "json",
    type: "POST",
    data: {username: user, content: content},
    success: function(data) {
      if(data.status == 'success')
         alert("Inserted successfully.");
      else
          alert("Insertion failed.");
    }
    });

In the PHP get the username and content values using $_POST['user'] and $_POST['content'].
Once the database insertion succeeded, echo {"status": "success"}. If Insertion failed, echo {"status": "error"}.
 
Back
Top Bottom