SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JSONP error message saying "parseerror"

    I am using codeigniter along with a jquery ajax call. I get a response from the server but when I try to alert the data contained from the response it just says "parseerror", how do I get the entire data, see my code below:

    I get this response, alongside an error in Firebug:

    http://domain.com/179/index.php/api/...=1338198528789

    ERROR

    missing ; before statement

    </div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"


    VIEW

    Code:
                $(document).ready(function(){
                   $.ajax({
    					url: "http://domain.com/179/index.php/api/user",
    					data: "format=jsonp&id=1",
    					dataType: "jsonp", 
    					type: "GET",
    					success: function(data) {
    					var json = $.parseJSON(data);
    					
    					alert(json)
    					},
    					error: function(err, msg){
    					var json = $.parseJSON(data);
    					
    					alert(json)
    					
    					}
    				}); 
                })
    CONTROLLER

    PHP Code:
    class Api extends REST_Controller  
    {  
        function 
    user_get($x)  
        {  
            
            
    $id $this->get('id');
            
            if(!isset(
    $id))  
            {  
                
    $this->response(NULL400);  
            }  
            
            
    // validate user
            
            
    $this->load->model('model_admin');
                         
            
    $user =    $this->model_admin->get_data($id);

      
            if(
    $user)  
            {  
                
    $this->response($user200); // 200 being the HTTP response code  
            
    }  
      
            else  
            {  
                
    $this->response(NULL404);  
            }  
        } 
    The JSON contained inside http://domain.com/179/index.php/api/user

    Code:
    ([{"id":"1","first_name":"John","last_name":"smith"}])
    Also, for example, I would like to alert John smith (from above json).. how would I do that in the view??

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,800
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Possibly the invalid () wrapped arount the array.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •