0

Can anyone help detect what I'm doing wrong... I am a beginner so I could not be more lost.

This is what I have:

Service class with this get method:

void OtvoriKonekciju()
    {
        uredjaj = new DBBL();
        uredjaj.entity.Connection.Open();
    }
void ZatvoriKonekciju()
    {
        uredjaj.entity.Connection.Close();
        uredjaj.entity.Dispose();
    }
public Uredjaji getUredjajPoID(int uredjajID)
    {
        OtvoriKonekciju();
        //stored procedure call
        Uredjaji list = uredjaj.entity.stp_getUredjajPoID(uredjajID).SingleOrDefault();
        ZatvoriKonekciju();
        return list;
    }

frmUredjaji.aspx.cs:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Uredjaji getUredjajByID(int uid) {
    return uredjaj.getUredjajPoID(uid);
}

frmUredjaji.aspx:

$("table.dxgvTable_HDesk > tbody > tr").on("click", function () {

            // Removes any detail rows from data grid (using free version of a DevExpress dgv control)
            $("table.dxgvTable_HDesk > tbody > tr#details").remove();

            // Gets the id from hidden column (table uredjaji)
            var idnumber = $(this).find(".refIDdata").text();

            //till here is ok, i get the text whic is ID 
            //(do i need, and how, to convert it to int somehow?)

            $.ajax({
                type: "POST",
                url: "frmUredjaji.aspx",
                data: "{uid:idnumber}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: OnSuccess,
                error: OnError
            });

        });
        function OnSuccess(data) {
            var temp = data.d.KlijentID;
            alert("All OK, result: "+temp);

        }
        function OnError() {
            alert("Error getting data!");
        }

I get the column text without problems but the ajax is always returning error message specified in OnError().. I guess it has something to do with ajax and how i return data, well i am noob so please help

EDIT: OK this is what I was trying to do...

When I click on a row I want to show additional data below (I want to use it on grids with many columns that cant fit into my page width. Something like a row detail that is not supported in a free version of a DevExpress data grid I am using.

2
  • change data: "{uid:idnumber}", to data: {uid:idnumber}, Commented Nov 7, 2014 at 11:48
  • @rt2800 Didn't work ... thanx anyway Commented Nov 7, 2014 at 12:11

2 Answers 2

1

You can try the ajax call in this way. Hope it helps you.

Try Ajax call this way,

var idnumber ="dataToBeSent";`
var rawData={"uid":idnumber}; 
var finData= JSON.stringify(rawData);
 $.ajax({
            type: "POST",
            url: "frmUredjaji.aspx",
            data: finData,
            dataType: "json",

            success: OnSuccess,
            error: OnError
        });
Sign up to request clarification or add additional context in comments.

6 Comments

I was trying to select "anything" in specified tr td since it's a column representing ID and is only text. I wanted to pass it as ID so i can get other data connected to that id. I choose only KlijentID just for testing. ... it didn't work with this either ... I must be doing some basic stuff wrong...
Yes, I'm not clear on what data can pass and in which way and format so many mistakes on my side sorry I want to pass a value so i can use it later in stored procedure. Console output: Failed to load resource: net::ERR_CACHE_MISS
Hmm... script is in MasterPage and I have sub folders for pages localhost:someport/Poslovanje/frmUredjaji.aspx is Browser URL if I change ajax URL to Poslovanje/frmUredjaji.aspx it says 'POST localhost:55610/Poslovanje/Poslovanje/frmUredjaji.aspx 404 (Not Found) jquery.min.js:4send jquery.min.js:4m.extend.ajax jquery.min.js:4(anonymous function) frmUredjaji.aspx:60m.event.dispatch jquery.min.js:3r.handle' so I think it was right the first time with just frmUredjaji.aspx But still not working ... please be patient with me I'm so confused about everything right now thanx
If u want to know the folder structure ... MasterPage(root)>Poslovanje(folder)>frmUredjaji.aspx url: "/Poslovanje/frmUredjaji.aspx" and url: "frmUredjaji.aspx" returns same console output: Failed to load resource: net::ERR_CACHE_MISS other URL changes return console output like in the comment above Which means still not working
OMG, I totally got it wrong ... in url there should be page/method but i didn't know that soooo stupid. Well my test SQL server is down but I'll try it tomorrow when I find the time and post about it
|
0

Eureka I've made it work. Its a little messy code but it works just fine hehe. Didn't work with objects for me (couldn't figure it out) so I returned only a string with everything I wanted and it worked.

C# (if statements for fields that have NULL (else exception is thrown on NULL value)

static UredjajiServis uredjaj = new UredjajiServis();
static KlijentServis klijent = new KlijentServis();
static NaruciteljServis narucitelj = new NaruciteljServis();
List<Lokacije> list;
static LokacijeServis lokacije = new LokacijeServis();
[WebMethod]
    public static string ubaciUredjaj(int uid)
    {

        Uredjaji temp = uredjaj.getUredjajPoID(uid);
        string imeNarucitelja = string.Empty, prezimeNarucitelja = string.Empty, nazivKlijenta = string.Empty, nazivLokacije = string.Empty;
        int klijentID = Convert.ToInt32(temp.KlijentID);
        if (klijentID != 0)
        {
            Klijenti tempKlijent = klijent.getKlijentPoID(klijentID);
            nazivKlijenta = tempKlijent.Naziv;
        }
        else
        {
            nazivKlijenta = "&nbsp;";
        }
        int naruciteljID = Convert.ToInt32(temp.NaruciteljID);
        if (naruciteljID != 0)
        {
            Narucitelji tempNarucitelj = narucitelj.getNaruciteljPoID(naruciteljID);
            try
            {
                imeNarucitelja = tempNarucitelj.Ime;
                prezimeNarucitelja = tempNarucitelj.Prezime;
            }
            catch
            {
                naruciteljID = 0;
            }
        }
        else
        {
            imeNarucitelja = "&nbsp;";
            prezimeNarucitelja = "&nbsp;";
        }


        int lokacijaID =Convert.ToInt32(temp.LokacijaID);
        if (lokacijaID != 0)
        {
            Lokacije tempLokacija = lokacije.getLokacijuPoID(lokacijaID);
            nazivLokacije = tempLokacija.Naziv;
        }
        else
        {
            nazivLokacije = "&nbsp;";
        }

        string msg = string.Empty;

        msg ="<div class='dwrapper'>";
        msg += "<div class='detailrow'><span class='dlabel'>Klijent: </span><span class='ddata'>" + nazivKlijenta + "</span></div>";
        msg += "<div class='detailrow'><span class='dlabel'>Naručitelj: </span><span class='ddata'>" + imeNarucitelja + " " + prezimeNarucitelja + "</span></div>";
        msg += "<div class='detailrow'><span class='dlabel'>Lokacija: </span><span class='ddata'>" + nazivLokacije + "</span></div>";
        msg += "</div>";

        return msg;
    }

HTML/JavaScript/jQuery

$("table.dxgvTable_HDesk > tbody > tr").not(':first').on("click", function () {

        $("table.dxgvTable_HDesk > tbody > tr#details").remove();
        $("td", this).css("border-bottom", "2px solid #eee !important");
        $(this).after('<tr id="details" class="dxgvDataRow_HDesk"><td colspan="20" class="dxgv"><div class="detailswrapper"><span class="dloading">Učitavanje u toku ...<span></div></td><tr>');
        var idnumber = $(this).find(".refIDdata").text();

        $.ajax({
            type: "POST",
            url: "/Poslovanje/frmUredjaji.aspx/ubaciUredjaj",
            data: '{uid:"' + idnumber + '"}',
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: OnSuccess,
            error: OnError
        });

    });
    function OnSuccess(poruka) {
        $(".detailswrapper").html('<!--<span class="dtitle">Dodatne informacije:</span>-->' + poruka.d);
        $(".detailswrapper").fadeOut(0).fadeIn(1000);
    }
    function OnError(poruka) {
        alert("Greska pri dobavljanju informacija!");
    }

Thanks for all your help guys.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.