How to auto feed-in the data to the webpage? - c#

I'd like to ask if somebody has the idea on how to auto feed in the data to your webpage. What I mean is, if I'm uploading data to my website I want to automatically display it to the other page which is displayed in a separate tab because I have a photo gallery page and I want to see my uploaded files in that page without hitting the refresh button of the browser. All I've got right now is the auto-refresh codes but that doesn't apply it to this scenario. Other example is the news feed of your facebook. If your friend is posting something then it automatically be displayed to your news feed page, that is what I'm trying to get...I hope somebody can get my point. Thanks in advance.

Here is the "cool" stuff for realtime web in. Net: http://signalr.net/

You can make an AJAX call every, let's say, 5 seconds.
If you are using Jquery in your site, you can try:
var seconds = 5;
setInterval(function(){
$.ajax({
url: urlToHandler,
data: jsonData,
dataType: 'json',
type: 'POST',
contentType: 'application/json',
success: function(data) {
$('#container').html(data.html)
},
error: function(data, status, jqXHR) {
console.log('There was an error.');
}
}); // end $.ajax
}, seconds * 1000)

Related

Get data in background without affecting UI in .net + jquery

I need to create multiple search requests in Jquery which searches from different tables/pages and I need to combine all the search results to one HTML table and show the results in UI.
Below is my approach..
Using $.ajax in Jquery, I go to the server (.Net Code), fetch JSON data, come back to the JS file and build a HTML table and display result (this result will have checkbox for user to check/uncheck the results). Once I display results, I again use $.ajax, go to server (.NET Code) and get data and will append the results to the first HTML table.
My requirement is, between these 2 requests I need to
1) Show a Loading image/text.
2) The user should be able to access (scroll, check, uncheck) the HTML table results returned by 1st JSON request.
I am able to accomplish 1) also. The problem I am facing is regarding 2).
Once the results come from 1st request and once I display the results in a div, I again trigger the 2nd search request using $.ajax. At this time I am not able to access the HTML table. The page freezes until the results from the second request come and till I bind the results to HTML table.
My code is something like this.
function SearchDetails() {
GetDetails("Test", 0); /*Trigger First Request*/ }
function GetDetails(searchKeyword, iAppend) {
$.ajax({
type: "POST",
url: "FETCH_DETAILS.asmx/GetDetails",
data: "{'searchKeyword':'" + searchKeyword + "', 'Append':'" + iAppend + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
crossDomain: true,
jsonp: false,
success: function (response) {
if(iAppend == 0) //First Request
{
BindTable(response.d, iAppend); //Creates new HTML table and binds results
GetDetails("TestNew", 1);//Trigger Second Request
}
else if (iAppend == 1) {
BindTable(response.d, iAppend);
}
},
failure: function (msg) {
alert(msg);
},
});}
function BindTable(SearchResults, iAppend){
/*Creates HTML Table & binds to a div for First Request
Creates HTML Table Rowss & appends to existing HTML table for Second Request*/ }
Please suggest me whether i am missing anything or is there a way to go to server(.NET code) from Jquery without affecting (getting freeze) the display/UI.
Perhaps set the:
async: false
to
async: true

processing ajax post on the server using c#

I'm trying to do something that's very new to me. I've done some digging but what I've come up with only had solutions by using some kind of .aspx page to process forms.
What I'd like to do is send some form input via ajax (I'm using jquery) to the server to be processed by c#.
This is, I believe, a fairly general question. It doesn't have to do with submitting form input specifically, but more about how to send some data to be processed by c# in the backend.
I want to make an ajax POST to a certain page for processing such as this:
$.ajax({
type: "POST",
url: "****???****",
data: { name: "Bob", gender: "Male" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
}
});
Now, my question is, what kind of file/page can I use for the url value in the above ajax call, that will be able to handle the POSTed data using c#?
All the examples I've seen use a .aspx page that processes the form and sends it to a .cs code-behind page. If possible, I'd like to be able to use something other than an .aspx page.
The site I'm working on is using just HTML as I'm working with angular. Is there any other way I can handle ajax on the server in a way that I can use c#?
To be very specific, I'm trying to setup a registration page where a user puts in their username and password. I need the password to be sent to the server to have a hash and salt created in C#.
Thanks, and please let me know if you need any additional information to continue.
Try this
In code behind file:Default.aspx.cs
[WebMethod]
public static void GenerateHash(string name,string password)
{
//Write logic to generate hash
}
.aspx page
$.ajax({
type: "POST",
url: "Default.aspx/GenerateHash",
data: { name: "xxx", password: "xxxx" },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
}
});

Jquery Ajax multi user request

I am very new into ajax and i am having a strange problem, I have created an asp.net website that have a web service within the project I am calling this web service by following ajax code:
$.ajax({
type: "POST",
url: pageUrl + "/PassData",
data: JSON.stringify({ aos_code: code }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessCall
});
the c# code is not very complicated, basically it will get the code and call the stored procedure and return some value:
[WebMethod(EnableSession = true)]
public string[] PassData(string aos_code)
{
// calling the database and returning some data
return data;
}
And it works fine; the problem is that if two different users accessing the application in the two different computers and let say they clicking a button at the same time to call the server side function via Ajax, it will return the “500 internal server error”.
I am not sure how exactly Ajax work, is request are belong to same session or all user requesting a single function?
Hope it makes sense, and I would really do appreciate for the clarification and help.
Regards,
Error 500 indicates that something went wrong on the server side. Check your console (firebug or similar) to see what exactly happened and try to fix it. Ajax has nothing to do with it, it is simply as if two users visited the same page at the same time.

Progress Bar while sending ByteArray to Server through Action Method in MVC 3

I have a byte-array that i upload to the server through action method from javascript (MVC3):
$.ajax({
url: '#Url.Action("Upload")',
type: 'POST',
contentType: 'application/x-amf',
processData: false,
data: ByteArrayData,
success: function (result) {
alert(result);
}
});
I was wondering what is the easiest way to make a percentage progress bar while the bytes are getting sent to the server?
Easiest way would be to Mask the content using javascript or show Javascript progress bar on view, until you get the response back from Server.
My initial (and boring) response is that this would be hard to do, but I'm not wise enough with the HTTP post request to completely be sure if it is or isn't possible. Essentially though you'd have to either know:
Size of posted data
Upload speed
OR
Size of posted data
Data sent each interval (if such a thing even exists?)
I'm not sure you can access either of these combinations with JavaScript. You'd probably need to use some sort of flash uploader for this.

500 - Internal server error. how i can solve it in asp.net MVC 3 on server?

I deployed a mvc 3 project.
The server gave an error 500 - Internal server error. Nothing else.
How can I get more detail about it. How can I know the reason behind it, because there is nothing going wrong in my code in my development machine.
Since I just have FTP access, is there a way for me to create a log and get all the information about the error in detail.
are their any possible thing i can do that i can see the error in my browser. no problem because i deploy on testing domain.
You will get a 500 error if the web.config xml is invalid. Find out if is invalid by opening IIS Manager, and for the site double click on one of the features (Authorization, HTTP Redirect). If the xml is invalid, it will display a message box with an error and a line number.
If the web config is ok, configure customErrors so you can the errors.
http://msdn.microsoft.com/en-us/library/h0hfz6fc(v=vs.100).aspx
This might display some more detailed information.
Please make sure is ASP.Net MVC installed on the server? or Is the correct version of IIS installed on the server?
Check that the data is out of ajax like data_.
var data_ = { indexNum: index };
$.ajax({
type: "POST",
url: "/Home/ExamsById",
data: data_,
dataType: 'json',
success: function (response) {
$(".cont-exams").slideToggle();
}
});
Check that the data is out of ajax like data_.
var data_ = { indexNum: index };
$.ajax({
type: "POST",
url: "/Home/ExamsById",
data: data_,
dataType: 'json',
success: function (response) {
$(".cont-exams").slideToggle();
}
});

Categories

Resources