|
Some of you know that I've been working on a SignalR app that updates web clients in real time. The only part I couldn't get working was the JavaScript part. I just now got it working!! See my comment in line
var searchUrl = "Index/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
}
});
I'm so happy!! Being a Desktop guy I've never done any real web work before. I know have a WebGrid refreshing in real time in my project!!
Thanks for all of you who tolerated me during this experience!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
I'm no SignalR expert, but isn't that only going to call the server once? I'd think you'd need something like a persistent connection to keep real time data streaming over?
SignalR JS Client · SignalR/SignalR Wiki · GitHub
I could be wrong though, I've never used it?
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
Brent Jenkins wrote: 'd think you'd need something like a persistent connection to keep real time data streaming over?
That's exactly what SignalR is for. It maintains a connection between the client and server.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yes, that persistent connection is part of SignalR's jquery library but it looked like you were just using a standard jquery ajax call instead of that in your original post?
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
The goal is to 'catch' a SignalR callback in the browser and reload the grid. That seems to be working as I have it.
Brent Jenkins wrote: it looked like you were just using a standard jquery ajax call instead of that in your original post?
I think I need a better explanation of this. We can move this to the Web forum if needed.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
As I say, I'm not familiar with SignalR but this code looks like a standard client->server jQuery ajax call (i.e. not SignalR)..
var searchUrl = "Index/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
}
});
This is a single, asynchronous call to the server initiated from the client (web browser).
Now I'm just taking all this from the QuickStart Persistent Connections · SignalR/SignalR Wiki · GitHub website..
For SignalR to work (i.e. keep constantly streaming data one way or another) it looks like you need to add the SignalR client side library to your page:
<script src="Scripts/jquery.signalR-1.1.1.min.js" type="text/javascript"></script>
And call your server like this:
$(function () {
var connection = $.connection('/echo');
connection.received(function (data) {
$('#messages').append('<li>' + data + '</li>');
});
connection.start().done(function() {
$("#broadcast").click(function () {
connection.send($('#msg').val());
});
});
});
One way to tell might be to put a breakpoint in either you client side or server side code and see if data is constantly being sent.
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
There's more to it than I originally posted:
<script src="/Scripts/jquery-3.1.1.min.js"></script>
<script src="/Scripts/jquery.signalR-2.1.2.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
<pre>
var conn = $.hubConnection("http://blah:8094/signalr");
var proxy = conn.createHubProxy('dashboardHub')
proxy.on('notifyAllClientsOfChanges', function () {
console.log("notifyAllClientsOfChanges received");
var searchUrl = "Index/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
}
});
});
conn.start().done(function ()
{
console.log("Connected!!!");
}).fail(function (e)
{
console.log('Unable to connect:' + e);
});
});
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yep, that looks like what I was seeing on the SignalR docs site..
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
Wait... If I get this right you wait for a notification from SignalR and then refresh all your data using a regular AJAX call.
Why not simply send the changed data with your SignalR notification?
It saves you an entire AJAX call (and a lot of AJAX calls when you have multiple clients)!
|
|
|
|
|
Good point. Please see this.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: See my comment in line
var searchUrl = "Index/GetData"; Amazing that code works when you do it right.
Code has 0 intelligence and 100% obedience. It only does exactly what it is told too. Nothing more and nothing less.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
RyanDev wrote: Code has 0 intelligence
Code Kevin has 0 intelligence
FTFY
I went into this with ZERO web experience. The fact I got this working is total luck.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Kevin Marois wrote: ZERO web experience. Wow. signalR is one way to dive right in. As you have no doubt figured out, programming for the web is a very different model than programming for Windows apps.
Good job.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
SignalR is actually very simple. I'm using it on a couple of Windows projects. The grief this time was intregrating into a Web app.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Congratulations, Kevin !
«When I consider my brief span of life, swallowed up in an eternity before and after, the little space I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which know me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.» Blaise Pascal
|
|
|
|
|
You should maybe extend your in-line documentation to explain why it didn't work.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Spam of the day...
"Our company is expanding... blah, blah, blah....
If this sounds good to you, please apply."
But no link is given or other obvious method to apply... deleted, but still laughing.
|
|
|
|
|
Reply: "I have no opinion on the expansion of your company, but if it makes you happy, go for it!"
|
|
|
|
|
As long as you opened it in text-only mode.
Otherwise, check your windows logs for other things that ran at the time you opened it.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
|
|
This has to be the best 404 message I've ever seen. Check it out
[^]
|
|
|
|
|
I dunno, I just moved along...
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|