speranza4ever
speranza4ever

Reputation: 61

Owerwrite to a div element with Jquery

My problem is, i am getting a html text os string doesnt matter what is it from jquery but when i printed it inside a div element it doesnt clean the old data inside.

div is so simple just like that

<div id=table runat=server>

and my script is here

function send(inputa, inputb) {

     var dataString = JSON.stringify({
         Id: inputa,
         Opt: inputb                 
     });

     $.ajax({
         type: "POST",
         url: "my.aspx/myfunction",
         data: dataString,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (result) {
             alert(result.d);  // here i can see calue is good
             $("#ctl00_ContentPlaceHolder2_tablo").empty(); // here i try to clean
             $("#ctl00_ContentPlaceHolder2_tablo").html(result.d);
            },
         error: function () {
             alert("Problem Occured");
         }
     });

 }

Please let me know what is not good here. I tried all functions html text val, i need something more i guess. my output has old values aswell.

Upvotes: 0

Views: 60

Answers (2)

speranza4ever
speranza4ever

Reputation: 61

Okay after checking many times, I found what the problem was: I am using div element in table content and writing table columns inside this div. And when I render page this div is kicked out of table content. And jQuery is changing content like I wanted but table was still remaining. To fix this, I used table id and deleted all div elements in table.

Issue solved.

Thanks everybody for answers.

Upvotes: 0

T J
T J

Reputation: 43156

Your <div> is:

<div id=table runat=server>

so instead of

$("#ctl00_ContentPlaceHolder2_tablo").empty(); // here i try to clean
$("#ctl00_ContentPlaceHolder2_tablo").html(result.d);

use the correct id:

$("#table").empty(); // this is not necessary
$("#table").html(result.d); // this will clear the existing content

Upvotes: 1

Related Questions