0

The ajax call below is not going through. The function simply quits and neither of the alert messages below are shown. Any ideas why? I have placed a separate alert within the click function above the ajax call and it shows that the function is being called properly. This is my first time to use the jquery ajax and I am having a rough go of it.

I have soo many questions and I see so many different things. I see people with and without the .php on the url name. I see people with and without quotes on the data and around the url. Does anyone know the propor convention? Thanks.

$(document).ready(function() {
    $(".folderopen a").click(function(event) {
        e.preventDefault();        
        $.ajax ({
        type:'GET',
            url:'FolderOpen.php',
            data: {userid:10},
            success: function() {    alert('success');},
            error: function(){       alert('failure');}
            });  

    });
});
Joshua Foxworth
  • 1,236
  • 1
  • 22
  • 50

1 Answers1

0

try use this code :

$.ajax({
                type: "GET",
                url: "FolderOpen.php",
                data: {userid:10},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert('success');
                },
                error: function () {
                    alert('error');
                }
            });
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
  • Thanks, but that still produces no results. – Joshua Foxworth Nov 20 '12 at 07:45
  • @JoshuaFoxworth can you trace your XHR request with firebug? – Sirwan Afifi Nov 20 '12 at 07:48
  • @JoshuaFoxworth use 'POST' instead of 'GET' – Sirwan Afifi Nov 20 '12 at 07:50
  • Oh my heavenly stars. I looked at the fire bug and my problem was that I used e.preventDefault(); where I should have used "event" instead of "e". At least now i am getting an error which I will look into addressing. According to firebug, it is returning the "test" string from my php file. Incidentally, how can I trace my XHR request with firebug? – Joshua Foxworth Nov 20 '12 at 07:58
  • 1
    @JoshuaFoxworth you can use Network tab in firebug for Captuer and trac ajax request and response : https://getfirebug.com/network – Sirwan Afifi Nov 20 '12 at 10:30