3

I was previously using an older ver of the signalR.js and everything is fine except it is intermittently causing my page to hang therefore I want to test it out with a newer ver from downloaded from the SignalR github site.

I tried following the client side example of SignalR but I get this error when inspecting element in chrome,

Uncaught TypeError: Object # has no method 'sending'. Anyone came across this error?

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script> 
  <script src="/Scripts/jquery.signalR.js" type="text/javascript"> </script>    
  <script src="signalr/hubs" type="text/javascript"> </script>

        var hub = $.connection.testHub;
        hub.showMessage = function() {
                    $("#inboxcount").show();
                };

        $.connection.hub.start()
            .done(function() {
                hub.subscribe($('#<%= hdnUserId.ClientID %>').val());
            })
            .fail(function() {
                alert("Could not Connect!");
            });

TestHub.cs:

using System.Threading;

{
    /// <summary>
    /// Test Hub used to demonstrate the key concepts of SignalR
    /// </summary>
    [SignalR.Hubs.HubName("testHub")]
    public class TestHub : SignalR.Hubs.Hub
    {
        /// <summary>
        /// Broadcast the message to all clients
        /// </summary>
        /// <param name="message">message to be broadcasted</param>
        public void Broadcast(string message)
        {
            this.Clients.showMessage(message);
        }

        /// <summary>
        /// Return a string with the formate, Hello [current user name]
        /// </summary>
        /// <returns></returns>
        public string SayHello()
        {
            //Context property can be used to retreive HTTP attributes like User
            return "Hello " + Context.User.Identity.Name;
        }

        /// <summary>
        /// Simulates a long running process that updates its progress
        /// </summary>
        public void LongRunningMethod()
        {
            Thread.Sleep(1000);
            this.Caller.showMessage("25% Completed");
            Thread.Sleep(1000);
            this.Caller.showMessage("50% Completed");
            Thread.Sleep(1000);
            this.Caller.showMessage("75% Completed");
            Thread.Sleep(1000);
            this.Caller.showMessage("Done");
        }

        /// <summary>
        /// Subscribe to a given message category
        /// </summary>
        /// <param name="category">the category to subscribe</param>
        public void Subscribe(string category)
        {
            //Add current connection to a connection group with the name 'category'
            this.AddToGroup(category);
        }

        /// <summary>
        /// Publish a message to the given mmessage category
        /// </summary>
        /// <param name="category">the category to send the message</param>
        /// <param name="message">the message to be sent</param>
        public void Publish(string category, string message)
        {
            //Broadcast the message to all connections registered under the group 'category'
            this.Clients[category].showMessage(message);
        }
    }

Submit two forms to the same page

I have been on this site all day and can't seem to find what I need - no duplicate post intended.

I have a form containing a link which calls a modal popup containing a different form.

###### PARENT PAGE #############
<form...>
...
<a href="php_page.php?id=<?php echo $id; ?>&sect=<?php echo $sect; ?>">link</a>
...
</form>

**** MODAL POPUP ****
<form...>
...
<input type="submit" />
</form>
**** END MODAL POPUP ****

### END PARENT PAGE #############

When I submit the form in the modal popup, the parent page is refreshed to show the updated info in the corresponding section of the page; except that the first form is not submitted and when the page refreshes to update the necessary section, the contents of the first form is lost.

I have tried using ajax to refresh only the necessary section of the page but that doesn't work as the sections that need refreshing use php variables with contents from mysql.

The system does what it needs to do and I don't mind the refresh. But I need a way to keep the user data entered into the first form.

Is it possible to submit the first form at the same time as the second to the same php page or any other way of preserving the user data in the first form on page reload without submitting it.

4

2 回答 2

0

Add server or client in hub call hub.server.subscribe

于 2013-06-12T12:35:31.650 回答
0

你可能应该使用

 <script src="@Url.Content("~/signalr/hubs")" type="text/javascript"> </script>

代替

 <script src="signalr/hubs" type="text/javascript"> </script>

如果这没有帮助,你应该检查你的项目中是否没有任何旧的 SignalR 库:所以删除每个 SignalR dll,并添加:

  • Microsoft.AspNet.SignalR.Core
  • Microsoft.AspNet.SignalR.Hosting.AspNet
  • Microsoft.AspNet.SignalR.Hosting.Common

这对我有用:)

于 2012-12-21T15:07:26.550 回答