views:

42

answers:

1

I am using the jquery $.Ajax property for getting some data from database as json and manipulating dom with that.

For example like this:

$.ajax({
  type: "POST",
  url: "TipsAndTricksService.asmx/postCommentForTT",
  data: "{'ttID':'" + ttID + "','text':'" + answerText + "','authorOfTT':'" + authorOfTT + "'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function(message) {    
        var a=message.d;
        var newCommentDiv = document.createElement('div');
        newCommentDiv.setAttribute('id',a.answerID+"_commentTT");
        newCommentDiv.setAttribute('class',"answerDivStyCom"); 

        var html =  "<div class='leftUp'>"+
                        "<img alt='profilePic' src='images/profilepics/" + a.authorID + "_2.png'/>" +
                    "</div>"+
                    "<div class='middleUpStyCom'>"+
                        "<div class='middleUpUpStyCom'><a href='ProfileMain.aspx?pid=" + a.authorID + "' >" + a.authorName + " " + a.authorSurname + "</a></div>" +
                        "<div class='middleUpMiddleStyCom'>"+a.authorJobname+"</div>"+
                    "</div>"+

                    "<div class='leftDownStyCom'>"+
                        "<div class='leftDownUp'>+Şikayet Et!</div>"+

                    "</div>"+
                    "<div class='middleDownStyCom'>"+a.text+"</div>"+
                "</div>";

          newCommentDiv.innerHTML=html;
          $(myDiv).parent().parent().prev().append(newCommentDiv);
          $("#"+a.answerID+"_commentTT").hide().fadeIn(1000);
          $(myDiv).prev().children("textarea").val("");

  }
});

As you see: the url is a webservice function and it works fine.

The question is :

  • Is caching a default property of jquery ajax post request? if so how can i test it?
  • If not a default property, is there a good and safe plugin for that ?

Thanks

+1  A: 

Caching "POST" requests is kind-of weird, and your browser won't want to do it because a "POST" is supposed to mean that you are doing something actively on the server. For "GET" requests, things are cached the same way the browser caches anything else, with the exception that jQuery will modify your "GET" URLs with dummy parameters if you tell it to (the "cache" property you pass in the argument object to "$.ajax()").

What sort of caching are you talking about? It would help to know that.

Pointy
I am not quite sure to use POST or GET method for requests. I just mean caching the responses so that i dont have to go back to server for retrieving data. In this specific function, I have to go to server to post the answer, but in some other cases that i have in my project, there is only retrieving something from database. In these cases, i want to use caching.
mkafkas