0

I am calling a web method from asp.net 1.1 site and getting a response.

I use this object to populate some data, Now I want to store this object so that I can also save this data in database while saving click event.

How can I achieve this.

 $(document).ready(function () {
            $("#Ok").click(function () {
                $.ajax({
                    type: "POST",
                    url: "/Service.svc/xyz",
                    data: JSON.stringify(jData),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (**msg**) {
                        // STORE THIS msg object.
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                    }
                });
            });
        });
James
  • 2,136
  • 3
  • 23
  • 42
  • what is returning from /service.svc/xyz? if you want to save returning object in database, you can send another ajax request from success:function(data){ console.log(data); //do ajax request from here} – kidz Oct 25 '12 at 10:57
  • No..it is returning a object, which contains many information in json format..I have to go through the object later on and store what ever I want from that.. – James Oct 25 '12 at 10:59
  • If it's json format object, you can easily go through that object. Example: data.item, data.name based on if your json object contains key: item, name. What exactly you want else? – kidz Oct 25 '12 at 11:05
  • Now I want to store this object to SOME HIDDEN field or so..so that while saving the form i can use that values. – James Oct 25 '12 at 11:07
  • I am writing that solution in my answer, check if it's ok – kidz Oct 25 '12 at 11:10
  • any progress on the solution? – kidz Oct 25 '12 at 12:01
  • http://stackoverflow.com/questions/3448831/store-return-json-value-in-input-hidden-field..This helped much..anyways thanks for the ans. – James Oct 25 '12 at 12:02
  • Is there any difference between my solution and the link you provided? If you think my solution is ok, you can select it, no? – kidz Oct 25 '12 at 12:04

2 Answers2

0
$(document).ready(function () {
            $("#Ok").click(function () {
                $.ajax({
                    type: "POST",
                    url: "/Service.svc/xyz",
                    data: JSON.stringify(jData),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(data, textStatus, jqXHR){
                        // STORE THIS msg object.
                        /* now you can store data object to where you want to store.*/
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                    }
                });
            });
        });
brightboy2004
  • 258
  • 1
  • 3
0
$(document).ready(function () {
        $("#Ok").click(function () {
            $.ajax({
                type: "POST",
                url: "/Service.svc/xyz",
                data: JSON.stringify(jData),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data){
                    // STORE THIS msg object.
                  //if hidden field has id 'name'
                  $('#name').val(data.name);//if json object contains a key 'name'
                  //if hidden field has class name
                  $('.name').val(data.name);
                  //if hidden field name is name <input type="text" name="name" />
                  $(document).filter(':[name=name]').val(data.name)
                  //do the same for all elements to save
                },
                error: function (jqXHR, textStatus, errorThrown) {
                }
            });
        });
    });
kidz
  • 308
  • 1
  • 8