I do not know the fields you're querying but I can get you started.
--This example shows how to use the web api with the mvc controller. This might not be what you need but it is a little easier to understand and use, just my personal opinion.
-SQL Query
--ID should be a incremental primary key
create proc proc_GetRecords
@LastRecordID INT
AS
SELECT * FROM MyTable mt WHERE mt.ID > @LastRecordID
//when the window opens call your MVC controller
window.onload=function(){
//if you did not pass a lastrecordID check the localstorage of the browser
function GetRecords(lastrecordID) {
lastrecordID = lastrecordID || window.localStorage.getItem('lastrecordID');
$('div').dialog({
autoOpen: true,
height: 'auto',
width: 'auto',
//position: [$(e.target).position().left,
// $(e.target).position().top + 40],
open: function (event, ui) {
$.ajax({
type: "GET",
cache: false,
//the web api controller your working with
url:'api/lastestrecords?id='+lastrecordID,
async: false,
success: function (data) {
lastrecordID = data.records[data.records.length-1].ID
if (!lastrecordID || lastrecordID <1) {
//no new record then return with out doing anything
return;
};
//store the last lastrecordID in localstorage
window.localStorage.setItem('lastrecordID', lastrecordID);
//do something with the records
data
}
});
}});
}
}
--web api controller
public class LastestRecords : ApiController
{
public HttpResponseMessage Get( int id)
{
//var lastestRecords= //call sql query context.proc_GetRecords(id);
return Request.CreateResponse(HttpStatusCode.Created, new { records = lastestRecords }); ;
}
}