How to reload/refresh datatables without loading page.

How to reload/refresh datatables without loading page.

progy85progy85 Posts: 3Questions: 2Answers: 0

Hi,

I want to try using:
$('#Relacije').DataTable().clear();
$('#Relacije').DataTable().ajax.reload();

but I got:
DataTables warning: table id=Relacije - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Maybe is problem with my WebMethod?

Please check my all code:

//Shrani relacijo v potni nalog
[WebMethod]
public string shraniRelacijovPotniNalog(string username, string password, int IdPodjetja, string datumrelacije, string relacija, decimal kilometrov, decimal kilometrina, string opisnamena, bool kilometrinatujina, int ddlVoziloValue, int IDNaloga)
{
if (Membership.ValidateUser(username, password) && IdPodjetja != null)
{
//Najdi osebno/službeno vozilo
var vrstavozila = (from c in db.tbl_avtomobilis
where c.ID == ddlVoziloValue
select c).SingleOrDefault();

        //Pridobi najvišji ID
        var QueryMax = (from y in db.tbl_PotniNalogis
                        where y.Idkreiranopodjetje == IdPodjetja
                        select y.ID).Max();


        //Vozilo, ki je na leasing
        var avtomobilnaleasing = (from p in db.tbl_avtomobilis
                                  where p.ID == ddlVoziloValue
                                  select p).SingleOrDefault();


        tbl_relacije tbl_relacije = new tbl_relacije()
        {

            //     UserId = UserID,
            Idkreiranopodjetje = IdPodjetja,
            IdSifra = QueryMax,
            DatumRelacije = Convert.ToDateTime(datumrelacije), //txtDatum.SelectedDate.Value,
            IDRelacija =IDNaloga, //QueryMax,
            //  UserId = ("string test " ),
            Relacija = relacija,
            Kilometrov = kilometrov, //Convert.ToDecimal(txtKm.Text),
            CenaKm = kilometrina, //Convert.ToDecimal(txtKilometrina.Text),
            Kilometrina = (vrstavozila.TipVozila == "zasebno" || avtomobilnaleasing.Leasing == true) ? kilometrov * kilometrina : 0, //,
            OpisNamena = opisnamena,
            KilometrinaTujina = kilometrinatujina,

        };

        List<tbl_relacije> ie = new List<tbl_relacije>();


        ie.Add(tbl_relacije);
        db.tbl_relacijes.InsertAllOnSubmit(ie);
        db.SubmitChanges();

        //View relacije
        ////ViewRelacije.DataSource = (from p in db.tbl_relacijes
        ////                           where p.IDRelacija == QueryMax && p.Idkreiranopodjetje == Convert.ToInt32(Session["ID"])
        ////                           orderby p.DatumRelacije
        ////                           select p);
        ////ViewRelacije.DataBind();

    }
    return "OK";
}

string prikazpripetihrelacij;
//Relacije pripete k potnemu nalogu
[WebMethod]
public string PripeteRelacijeKPotnemuNalogu(string username, string password, int IdPodjetja, int IDNaloga)
{
    if (Membership.ValidateUser(username, password) && IdPodjetja != null)
    {
        //relacije
        var relacije = from p in db.tbl_relacijes
                       where p.IDRelacija == IDNaloga && p.Idkreiranopodjetje == IdPodjetja
                       orderby p.DatumRelacije
                       select new { ID=p.ID, Relacija = p.Relacija };

        prikazpripetihrelacij = new JavaScriptSerializer().Serialize(relacije.ToList());

    }
    return prikazpripetihrelacij;
}

How can I resolved with refresh without load or refresh page?

Thank you

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    but I got:
    DataTables warning: table id=Relacije - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

    Did you follow the troubleshooting steps in the link provided?
    http://datatables.net/tn/1

    What is the JSON response you get?

    Kevin

  • progy85progy85 Posts: 3Questions: 2Answers: 0

    This is my json:
    [{"ID":859863,"Relacija":"543"},{"ID":859864,"Relacija":"4"},{"ID":859867,"Relacija":"54"},{"ID":859868,"Relacija":""},{"ID":859869,"Relacija":"32"},{"ID":859870,"Relacija":"9"},{"ID":859871,"Relacija":"321"},{"ID":859872,"Relacija":"31231"},{"ID":859873,"Relacija":"432"},{"ID":859874,"Relacija":"43"},{"ID":859875,"Relacija":"43"},{"ID":859876,"Relacija":"00101"},{"ID":859877,"Relacija":"00101"},{"ID":859878,"Relacija":"00101"},{"ID":859826,"Relacija":"nova gorica-maribor"}]

    Is there any example how can i use Webmethod from c# to datatables using jquery?

    One example from this website does not works.

This discussion has been closed.