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 24, 2013 @ 07:19
    Tinku
    0

    The Umbraco Web Api Post Failed

    I am posting some values from a HTML page to the server via ajax. The value gets send from the Front end, but when the code hits the server, the values are null. Appreciate if someone could give some advice.

    I am Using Umbraco Version 6.1.5 with Mvc4 WEb API

    Server Side Controller

     public class SignInApiController : UmbracoApiController
    {
        private projectUmbracoContext db = new projectUmbracoContext();
    
        [HttpPost]
        public string signInOneOff([FromBody]SignIn model)
        {
            SignIn signIn = new SignIn();
    
            signIn.EmailId = model.EmailId;
            signIn.Password = model.Password;
            signIn.AppId = model.AppId;
            signIn.RegistrationDate = DateTime.Now;
            signIn.AppStatus = true;
            db.SignIns.Add(signIn);
            db.SaveChanges();
    
            return "success";
        }
    
    }
    

    To send value from client to api method I use a test.html page located on desktop with the following code

    <html>
    <head>
    <script src="jquery/1.10.2/jquery.min.js">
    </script>
    <script>
    
    function Internal() {
     var model = {};
    model.EmailId = "[email protected]";                              
    model.Password = "Tinku";
    model.AppId = "kk";
    
       alert("sdf");               
    $.ajax({
           type: "POST",
    
           url:   "http://localhost:1958/Umbraco/api/SignInApi/signInOneOff",
    
           data: JSON.stringify(model),
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           statusCode: {
           200: function (data) {
           console.log(data);
           alert("Success");                                        
           }
           },
           error:
           function (res) {
           console.log(res);
           alert("Failed");
           }
           });
     }
        </script>
          </head>
         <body>
    
        <button id="login2" onclick="Internal()">Internal</button>
         </body>
            </html>
    

    When use this html it actually hits the api but with null values and gives following error in inspect element network tab

    enter image description here

    Any help would be appreciated

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 24, 2013 @ 12:09
    Jeroen Breuer
    0

    Maybe you could have a look at this example to see what you might be doing wrong: http://www.nibble.be/?p=224

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft