Calling a webservice using simple AJAX

Calling a webservice using simple AJAX

by Thavarajan Mathivanan -
Number of replies: 1

Dear all this is my first post in Moodle, 

May i know what is wrong with this following code


    $(document).on('click', 'li', function(event) {

        var courseid = [{ 'courseid': event.target.id }];

        $.ajax({

                method: "POST",

                url: baseurl + "webservice/rest/server.php",

                data: {

                    wstoken: token,

                    moodlewsrestformat: 'json',

                    wsfunction: 'core_course_get_contents',

                    params: courseid

                }

            })

            .done(function(msg) {

                $('#coursecontent').html(JSON.stringify(msg));

            })

            .fail(function(data) {

                alert("error");

            });

    });

the ajax call is success, but it always return invalid parameter object as response , any clue



Average of ratings: -
In reply to Thavarajan Mathivanan

Re: Calling a webservice using simple AJAX

by Thavarajan Mathivanan -

found the solution

instead of 

 params: courseid

replace it with

courseid: event.target.id

Average of ratings: Useful (1)