0

I'm trying to clean up the html code on my site, so I moved the jquery code to an external js file. Almost everything works as before only a .get function stopped working.

$("#sle").live("click", function() {

    $.get("index.php", function(data){
        alert("Data Loaded: " + data);
    });


}); 

Any ideas?

Manuel
  • 7
  • 1
  • 2

4 Answers4

4

This is because the relative position of index.php has changed. it probably is now something like ../somefolder/index.php

makeitmorehuman
  • 11,287
  • 3
  • 52
  • 76
1

You're missing jquery library

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 
genesis
  • 50,477
  • 20
  • 96
  • 125
1

Open your browser's console and see if there are any errors. – Matt Ball 8 mins ago


Thats what it returns:dropdown.js:Uncaught TypeError: Object function $(id) { return document.getElementById(id); } has no method 'get' – Manuel 3 mins ago

The page is missing jQuery, or another function named $ is shadowing jQuery.

Try replacing replace $ with jQuery:

jQuery("#sle").live("click", function() {
    jQuery.get("index.php", function(data){
        alert("Data Loaded: " + data);
    });
});

However, if the error you commented on only appears when you try to use $.get() in the console, then you might be running into this issue in Google Chrome.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
0

You should probably need to use jQuery.ready() function like the one below:

 $(document).ready(function(){
    $("#sle").live("click", function() {
        //your code here...
        $.get("index.php", function(data){
            alert("Data Loaded: " + data);
        });
    }); 

 });

or same thing

$(function() {})
Tarik
  • 79,711
  • 83
  • 236
  • 349