mercredi 6 mai 2015

Saving data with ajax and json

I am working on a project that I didn't start and I have an input that is function is to save the data to the data base. The input leaves to this function (SaveData) and it isn't working. I really don't understand much from ajax and json, so could anyone please see what's wrong with this?

The function is this:

 function SaveData() {
     var columns = [];

     $("#FeaturedContent_m_visible_cols li").each(function (i, elem) {
        columns[i] = $(elem).attr("colid");
     });

     $.ajax({
        async: false,
        type: "POST",
        url: "http://ift.tt/1EPQ0gY",
        data: "{ 'jsonData': [" + JSON.stringify(columns) + "] }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
        },
        error: function (response) {
           alert(jQuery.parseJSON(response.responseText).Message);
        }
     });

The SaveConfiguration method is this:

[System.Web.Services.WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public static string SaveConfiguration(dynamic jsonData)
{
 Object[] column = (Object[])jsonData[0];
  string   col_id;
  int      i;

  for (i=0; i<column.Length; i++) {
     col_id = (string)column[i];
  }

  SaveTableConfiguration();

  return "";
  }

And the SaveTableConfiguration:

 public void SaveTableConfiguration(int list_id, List<TableHeader> lista)
  {
    int           i;
    TableHeader   row;
    SetListConfig set_lconfig = new SetListConfig(m_connection, m_language);

set_lconfig.LoadRecordset("LC_LISTID=" + list_id.ToString(),    m_transaction);
     while (!set_lconfig.IsEOF()) {
        set_lconfig.m_LC_EDITABLE = 0;
        set_lconfig.Update();

        set_lconfig.MoveNext();
     }

     for (i=0; i<lista.Count;i++) {
        row=lista[i];

set_lconfig.LoadRecordset("LC_LISTID=" + list_id.ToString() + " AND                LC_COLTBL='" + row.header_col + "'", m_transaction);
        if (set_lconfig.IsEOF()) {
           set_lconfig.m_LC_EDITABLE = 1;
           set_lconfig.m_LC_ORDER = i+1;
           set_lconfig.Update();
        }
     }
  }

Thanks Once more! =)

Aucun commentaire:

Enregistrer un commentaire