Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tinku 7 posts 53 karma points
    Oct 29, 2013 @ 11:36
    Tinku
    0

    'Parse Error' on returning value from my umbraco web api using JsonP

    I am using Umbraco 6.1.6 with MVC4 on Visual Studio 2012.

    I am using jsonp to return value from my umbraco web api. But the response on network tab of inspect element shows the response. But still I get parse error on client side.

    Server-side code

    public class LocaterApiController : UmbracoApiController
    {
       private proUmbracoContext db = new proUmbracoContext();
    
       [HttpGet]
       public IEnumerable<string> GetNearest()
       {
        return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
       }
    }
    

    client-side Code

     <!DOCTYPE html>
      <html>
       <head>
       <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
      <script>
      $(document).ready(function() {
        $( "#post").click(function() {
            alert('post');
            $.ajax({
                crossDomain: true,
                contentType: "application/json; charset=utf-8",
                url: "http://localhost:1958/Umbraco/api/LocaterApi/GetPost",
                data: { EmailId : "[email protected]" },
                dataType: "jsonp",
                success: onDataReceived,
                error: onError
            });
    
            function onDataReceived(data)
            {
                alert("Data received");
            }
            function onError(data,status)
            {
                alert(status);
            }
        });
    });
    </script>
    </head>
    <body>
    <input type="submit" id="post" value="Post"/>
    </body>
    

    I am returning values from server to client and on the network tab the status is shown '200 OK' and the response is

    ["Table","Chair","Desk","Computer","Beer fridge"]

    But it alerts a parse error.

    Hope some could point what I am doing Wrong.

    Any Help Would be Appreciated.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies