weardstuff
weardstuff

Reputation: 807

jquery/ajax problem

Is there anything wrong in my code? When I start the program, the proccess isn't doing anything. I want to retrieve information with jQuery's ajax function, from two functions from my controller, I use the Codeigniter framework. I access the functions by url: $(".SelectSubCategory").load("location/func2"). But like I said, nothing is happening.

$(document).ready( function() {

    $(".SelectCategory").change( function() {
        var category=$(this).val();
        var dataString = 'category='+ category;
        $.ajax
        ({
            type: "POST",
            url: $(".SelectSubCategory").load("location/func2"),
            data: dataString,
            cache: false,
            success: function(html) {
                $(".SelectSubCategory").html(html);
            }
        });
    });
    $(".SelectSubCategory").change( function() {
        var category=$(this).val();
        var dataString = 'category='+ category;
        $.ajax
        ({
            type: "POST",
            url: $(".SelectFunction").load("location/func"),
            data: dataString,
            cache: false,
            success: function(html) {
                $(".SelectFunction").html(html);
            }
        });
    });
});

Upvotes: -1

Views: 129

Answers (2)

locrizak
locrizak

Reputation: 12281

You need to retieve the url first and then make your ajax call. Something like this:

$.ajax({
    url:"location/func2",
    success: function(html) {
        $.ajax({
            type: "POST",
            url: val,
            data: dataString,
            cache: false,
            success: function(html) {
                $(".SelectSubCategory").html(html);
            }
        });
    }
});

Upvotes: 0

Chandu
Chandu

Reputation: 82893

Why are you assigning jQuery objects to the URL option of ajax calls i.e

url: $(".SelectSubCategory").load("location/func2")
url: $(".SelectFunction").load("location/func")

url option should be a valid URL of the same domain from where the page is loaded.

Something like: url:"location/func2" or url:"do/something/file.php" etc.

Upvotes: 1

Related Questions