MyCampaingPlugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hello,

I'm creating my own plugin to get data from my ERP system to MyCampaingPlugin.

I write plugin with adds table to nopCommerce database. I create a new Campaign and i want to load quotation from my system ERP to  @Html.EditorFor(model=>model.Body, "RichEditor").

My function in controller:


        [HttpPost, ActionName("Edit")]
        [FormValueRequired("order")]
        public ActionResult Order(MyCampaignModel _model)
        {
            _model.Body = GetMyOrder(_model.DocEntry);
            return Json(_model, JsonRequestBehavior.AllowGet);
        }


My View Edit.cshtml:


           <script type="text/javascript">

               $("#Order").click(function () {

                   alert('1');


                    $.ajax({
                           type: "POST",
                           url: '@Url.Action( "Edit", "MyCampaign")',
                           data: "model.DocEntry=1723",
                           success: function (msg) {
                               $('#inputName').val(msg.DocEntry);
                               alert("Body: " + msg.Body);
                           }
                       });

                       alert('2');
                   });

        </script>

@using (Html.BeginForm())
{  
    <input id="inputName"/>
    <input type="submit" id="Order" name="Order" class="t-button" value="@T("Order")" />
...



I tried many ways to sole this problem but java script dosn't fire  :( Why? Have any one idea ?
11 years ago
Hi,

your code might be trying to register the click event before the DOM is ready
try wrapping you code like this



$(function() {
$("#Order").click(function () {

                   alert('1');


                    $.ajax({
                           type: "POST",
                           url: '@Url.Action( "Edit", "MyCampaign")',
                           data: "model.DocEntry=1723",
                           success: function (msg) {
                               $('#inputName').val(msg.DocEntry);
                               alert("Body: " + msg.Body);
                           }
                       });

                       alert('2');
                   });
});


hope this helps
11 years ago
Hi Renzo,

I used

               $(document).ready(function () {


but still json dosn't work :(
11 years ago
:( can you see your javascript rendering in the page?
11 years ago
I have modified my script an its working but now i i want to put it to control @Html.EditorFor(model=>model.Body, "RichEditor")
How can I bind it ?



           <script type="text/javascript">

               $(document).ready(function () {

                   $("#Order").click(function () {

                    $.ajax({
                        type: "GET",
                        url: '/MyCampaign/Order/',
                        @*data: JSON.stringify(requestData),*@
                        data: ({ id: 50000 }),
                        dataType: 'json',
                        contentType: "application/json; charset=utf-8",
                        error: function (xhr) {
                            alert('Error: ' + xhr.statusText);
                        },
                        success: function (msg) {
                            alert("DocEntry : " + msg.Body);
                        }
                       });

                       return false;
                   });

                   var requestData = {
                       DocEntry: $.trim($('#inputName').val())
                   };

               });

        </script>


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.