ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to access Codeigniter Restul API using ajax

January 30, 2013 4:58am

Subscribe [1]
  • #1 / Jan 30, 2013 4:58am

    Roberto.A.Ferro

    4 posts

    I’m making a PhoneGap android app and I currently have the app and my restful service running fine I’m just struggling to get the app to get data from the rest api. When I type into the browser the following:

    <a href="http://localhost:8080/rest/index.php/api/practice/test/name/Peter/surname/Potter/format/json">http://localhost:8080/rest/index.php/api/practice/test/name/Peter/surname/Potter/format/json</a>

    The rest responds appropriately. Now I have the following code for the ajax call to the restful api PhoneGap:

    $(document).on('pagebeforeshow','#page2',
        function(){
                    $('#submit').click(function() 
                    {
                        var name = $("#username").val();
                        var surname = $("#usersurname").val();
    
                        alert(name + " " + surname);
    
                        $.ajax({ 
                               type: "GET",
                               dataType: "json",
                               url: "http://localhost:8080/rest/index.php/api/practice/test/name/"+name+"/surname/"+surname,
                               success: function(data)
                               {        
                                 alert("Working");
                               }
                            });
                    });         
                  });

    For some reason I cant get the rest api to send me the right data but I know its working 100%. I’m not to sure on how to fix this

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases