Get "Microsoft JScript runtime error" when add SignalR to MainSite.Master - signalr

Please help me. Our aps.net web application is using SignalR as the notifier, it uses a hub and works well for one page but when I added these lines of code to MainSite.Master:
<script type="text/javascript">
jQuery(document).ready(function (jQuery) {
var notifyHub = jQuery.connection.notificationHub;
jQuery.connection.hub.start();
});
</script>
Visual Studio throw the error message:
Microsoft JScript runtime error: Unable to get value of the property 'transports': object is null or undefined
Thanks for any help.

I resolved my problem by replacing:
jQuery.connection.hub.start();
by
$.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] });

Related

AngularJS asp.net MVC on IIS Server

I have an asp.net project that uses angular.js.
An example of the project can be found here:
https://www.codeproject.com/Articles/806029/Getting-started-with-AngularJS-and-ASP-NET-MVC-Par
When i attempt to run the project on my IIS Sever, the following function, which should return a string does not.
$http.post('Home/GetListOfVendors')
.success(function (response) {
console.log(response);
})
.error(function (response) {
console.log("error");
});
Instead, it returns the actual html file, along with all tags, etc.
Any help would be appreciated.

SignalR websocket failed during handshake

I'm working on a project in MVC of chat with SignalR.
I have bought a web host with Windows Server 2012 R2 with IIS8 and framework 4.5 and websockets enabled (more server details: http://www.register.it/hosting/windows/compare.html, I've got smart pack).
What my test application does is just a test for connect to hub in main page (I have another application, but I want to figure out what is the problem with minimum code possible), and when the client try to connect, this is the error:
WebSocket connection to 'ws://otaku2gether.com/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=VHGrwNoDXPMMbtM5dx1e2gF08%2FRWnVkbKUKjGkZkhE4I0p%2FpIFehvooO1shzCxkjU5f308%2FjleQIErTFsZqqe%2B1R4T2GRwMlO0IQbiZE9Z245YZcg6ipRF3cT1TOrqWB&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&tid=10' failed: Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing
The view is really simple:
#section scripts {
<script src="~/Scripts/jquery.signalR-2.2.1.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
<!--SignalR script to update the chat page and send messages.-->
<script>
$(function () {
var roomvar = $.connection.chatHub;
$.connection.hub.logging = true;
roomvar.client.sendBroadcast = function (message) {
alert(message);
};
$.connection.hub.start();
});
</script>
}
and the others prerequisites is done(helped also by the main tutorial https://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc ) like startup, and hub.
Does someone have some suggestions?

How to resolve crossdomain issues in Opeara when i consuming the webservice in Asp.net App?

jQuery.ajax({
type: "POST",
url: 'myserviceurl/GetName.ashx',
data: { name:"naresh"},
dataType: "text/plain",
xhrFields: {
withCredentials: true
},
beforeSend: function () {
alert("before send");
},
success: function (msg) {
alert("Success : " +msg);
},
error: function (err) {
alert("Error" +err);
}
});
I am using above Source code for Consuming the WebService in my Asp.Net Application.
My Service handler returns a string Message.
Above code working in IE9 with Success Message.
but When i run the application in Chrome /Opera i am getting the Success Message as null and some times showing undefined success.
In fiddler showing the Success Message but not in Browser(Chrome/Opera).
**Now i am getting below error : " XMLHttpRequest cannot load MYSERVICEURL.
Origin MYASP.NETAPPLICATIONURL is not allowed by Access-Control-Allow-Origin."
Now my question is :
Where i need to change in my code to run in the Chrome/opera ?
Note:
1)when i host ServiceHandler and Asp.Net WebApplication hosted into my IIS it's working in all Browsers.
2)Now i didn't hosted my Asp.Net WebApplication into iis , just i run into browser(Chrome and Operar) then i am getting above error.
Anybody suggestions would be appreciates.
Thanks in advance.
You have to use JSONP instead of jSON.
Also you should try
crossdomain: true

how to use json in asp.net 2003

I am using the JSON object with jquery in asp.net application. The code is working with VS2008 but when i moved sam code in VS2003 then it is showing the JSON is undefined. Code is following
var mes = $('#filePath').val();
alert("File Path: " + mes);
var jsonText = JSON.stringify({ sFilePath: mes });
In third line it is giving the error :
Microsoft JScript runtime error: 'JSON' is undefined
Can any one help on this. Do i need to add any reference.
Thanks in Advance
Eshwer N
This does not smell like an ASP.NET issue. Rather try including the json2.js as part of your script tags -
http://www.json.org/
https://github.com/douglascrockford/JSON-js
http://www.json.org/js.html
<script src="http://wherever.com/json2.min.js" type="text/javascript"></script>

How to process msg returned from jquery.ajax()

I would like to know what are the properties of msg object from jquery.ajax(). I am throwing an exception inside asp.net static function, but I am unable to cast it in javascript.
Thanks for help
You can read the response from your .Net page e.g.
$(function(){
$.ajax({
type: 'POST',
url: "test.aspx",
data: "ref=test",
success: function(r) { },
error: function(r) { alert(r.toString()); }
});
});
You can then read the error message and do the necessary steps..
If you have exception in the Server-Side, then JavaScript couldn't catch the Exception cause JavaScript is in the Client-Side.
You can catch the exception by yourself in Server-Side and send a custom error message to Ajax "success function" to handle the error(Exception) you thrown

Resources