locked
Update table Supplier with Jquery and Ajax RRS feed

  • Question

  • User-1278384752 posted

    Hello, 

    I am trying to update my table Supplier when user fill textboxes and when click on button.

    Is it possible to update table Suppler with jquery and ajax?

    My database consist of four tables: Supplier, Town, Street and Adress. 

    Columns of table Town: TownID(primary key), NameTown

    Columns of table Street: TownID,StreetID (composite primary key),NameStreet

    Columns of table Adress: TownID,StreetID,NumberAdress(all of these columns are composite primary key)

    Columns of table Supplier: SupplierID,NameSupplier,TownID,StreetID,NumberAdress,NumberOfPhone, Email

    This is my View: for ChangeSupplier


    @model FpisNada.Models.Dobavljac
    @{
    ViewBag.Title = "Index";

    Layout = null;
    }

    @Html.TextBoxFor(model => model.SupplierID, new { @placeholder = "pib dobavljaca", style = " float:left" })

    <div class="col-md-9">
    @if (ViewBag.ListaMesta != null)
    {
    @Html.DropDownListFor(m => m.TownID, ViewBag.ListaMesta as SelectList, "--select mesto--", new { @class = "form-control", style = " float:left" })

    }

    @Html.DropDownListFor(m => m.StreetID, new SelectList(""), "--select ulicu--", new { @class = "form-control", style = " float:left" })


    <div class="container">


    @Html.TextBoxFor(model => model.NumberAdress, new { @class = "form-control"})
    @Html.TextBoxFor(model => model.Email, new { @class = "form-control" })
    @Html.TextBoxFor(model => model.NameSupplier, new { @class = "form-control" })
    @Html.TextBoxFor(model => model.NumberOfPhone, new { @class = "form-control" })
    </div>
    </div>
    <input type="button" value="Edit" id="update"/>

    I appreciate any advice and help!

    Saturday, March 25, 2017 10:04 PM

Answers

  • User-271186128 posted

    Hi NadezdaJanjetovic,

    Is it possible to update table Suppler with jquery and ajax?

    Yes, it is possible. You could refer to the following code:

       <input type="text" id="txtName"/>
        <input type="button" id="btnGet" value="Get Current Time"/>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#btnGet").click(function () {
                    $.ajax({
                        type: "POST",
                        url: "/Home/AjaxMethod",
                        data: '{name: "' + $("#txtName").val() + '" }',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            alert("Hello: " + response.Name + " .\nCurrent Date and Time: " + response.DateTime);
                        },
                        failure: function (response) {
                            alert(response.responseText);
                        },
                        error: function (response) {
                            alert(response.responseText);
                        }
                    });
                });
            });
        </script>

    Code in controller:

       // GET: Home
        public ActionResult Index()
        {
            return View();
        }
     
        [HttpPost]
        public JsonResult AjaxMethod(string name)
        {
            PersonModel person = new PersonModel
            {
                Name = name,
                DateTime = DateTime.Now.ToString()
            };
            return Json(person);
        }

    More details, see:

    https://www.aspsnippets.com/Articles/ASPNet-MVC-jQuery-AJAX-and-JSON-Example.aspx

    https://www.codeproject.com/Articles/795483/Do-GET-POST-PUT-DELETE-in-asp-net-MVC-with-Jquery

    https://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 27, 2017 2:27 AM

All replies

  • User-271186128 posted

    Hi NadezdaJanjetovic,

    Is it possible to update table Suppler with jquery and ajax?

    Yes, it is possible. You could refer to the following code:

       <input type="text" id="txtName"/>
        <input type="button" id="btnGet" value="Get Current Time"/>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#btnGet").click(function () {
                    $.ajax({
                        type: "POST",
                        url: "/Home/AjaxMethod",
                        data: '{name: "' + $("#txtName").val() + '" }',
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            alert("Hello: " + response.Name + " .\nCurrent Date and Time: " + response.DateTime);
                        },
                        failure: function (response) {
                            alert(response.responseText);
                        },
                        error: function (response) {
                            alert(response.responseText);
                        }
                    });
                });
            });
        </script>

    Code in controller:

       // GET: Home
        public ActionResult Index()
        {
            return View();
        }
     
        [HttpPost]
        public JsonResult AjaxMethod(string name)
        {
            PersonModel person = new PersonModel
            {
                Name = name,
                DateTime = DateTime.Now.ToString()
            };
            return Json(person);
        }

    More details, see:

    https://www.aspsnippets.com/Articles/ASPNet-MVC-jQuery-AJAX-and-JSON-Example.aspx

    https://www.codeproject.com/Articles/795483/Do-GET-POST-PUT-DELETE-in-asp-net-MVC-with-Jquery

    https://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 27, 2017 2:27 AM
  • User-1278384752 posted

    Thank's for help, I will try that! 

    Best regards,

    Nadezda

    Monday, March 27, 2017 9:38 AM