Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to pass data from client to server in AJAX

How to pass data from client to server in AJAX

Scheduled Pinned Locked Moved ASP.NET
helpcsharphtmlsysadmintutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    engsrini
    wrote on last edited by
    #1

    Hi I am creating a chat application using ajax asp .net 2.0, here whenever the user enter the text message and hit enter, i have to pass this message to server in ajax, i am doing it right now using the following code

    url = 'Chat.aspx?action=chatmsg&u=' + userid +'&msg='+ txtMsg;
    
    req = getAjax();
    
    
    req.onreadystatechange = function(){
    //alert("req.readyState  "+req.readyState);
    	if( req.readyState == 4 && req.status == 200 ) {
    		updateAll();
    	}
    
    }
    
    req.open( 'GET', url, true );
    req.send( null );
    

    but the problem is some time the txtmsg (user entered message would be in html code). how to pass html formatted message to server using ajax. Please help Thanks SRini

    P C 2 Replies Last reply
    0
    • E engsrini

      Hi I am creating a chat application using ajax asp .net 2.0, here whenever the user enter the text message and hit enter, i have to pass this message to server in ajax, i am doing it right now using the following code

      url = 'Chat.aspx?action=chatmsg&u=' + userid +'&msg='+ txtMsg;
      
      req = getAjax();
      
      
      req.onreadystatechange = function(){
      //alert("req.readyState  "+req.readyState);
      	if( req.readyState == 4 && req.status == 200 ) {
      		updateAll();
      	}
      
      }
      
      req.open( 'GET', url, true );
      req.send( null );
      

      but the problem is some time the txtmsg (user entered message would be in html code). how to pass html formatted message to server using ajax. Please help Thanks SRini

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Are you getting any error ? Probably tage <> not allowed to send as message. However you can do one thing replace these tag with any special character on client side and then again parse it on server side.

      Parwej Ahamad R & D with IIS 5.0/6.0

      C E 2 Replies Last reply
      0
      • E engsrini

        Hi I am creating a chat application using ajax asp .net 2.0, here whenever the user enter the text message and hit enter, i have to pass this message to server in ajax, i am doing it right now using the following code

        url = 'Chat.aspx?action=chatmsg&u=' + userid +'&msg='+ txtMsg;
        
        req = getAjax();
        
        
        req.onreadystatechange = function(){
        //alert("req.readyState  "+req.readyState);
        	if( req.readyState == 4 && req.status == 200 ) {
        		updateAll();
        	}
        
        }
        
        req.open( 'GET', url, true );
        req.send( null );
        

        but the problem is some time the txtmsg (user entered message would be in html code). how to pass html formatted message to server using ajax. Please help Thanks SRini

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        By html encoding it first. For example, a space becomes %20.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        E 1 Reply Last reply
        0
        • P Parwej Ahamad

          Are you getting any error ? Probably tage <> not allowed to send as message. However you can do one thing replace these tag with any special character on client side and then again parse it on server side.

          Parwej Ahamad R & D with IIS 5.0/6.0

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Actually, there is a standard format for this already.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          P 1 Reply Last reply
          0
          • C Christian Graus

            Actually, there is a standard format for this already.

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            P Offline
            P Offline
            Parwej Ahamad
            wrote on last edited by
            #5

            Ok, Thanks Christian G

            Parwej Ahamad R & D with IIS 5.0/6.0

            1 Reply Last reply
            0
            • C Christian Graus

              By html encoding it first. For example, a space becomes %20.

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              E Offline
              E Offline
              engsrini
              wrote on last edited by
              #6

              Thanks for the reply, is there any built-in funtion to format the html messges or do we need to need manually parse all tags and convert it to a normal string? Thanks SRini

              C 1 Reply Last reply
              0
              • P Parwej Ahamad

                Are you getting any error ? Probably tage <> not allowed to send as message. However you can do one thing replace these tag with any special character on client side and then again parse it on server side.

                Parwej Ahamad R & D with IIS 5.0/6.0

                E Offline
                E Offline
                engsrini
                wrote on last edited by
                #7

                yeah if we appened the formatted html message with quering string, it is not even get called when httprequest.send is happened. Thanks SRini

                1 Reply Last reply
                0
                • E engsrini

                  Thanks for the reply, is there any built-in funtion to format the html messges or do we need to need manually parse all tags and convert it to a normal string? Thanks SRini

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  not sure in js. I would expect you'd find one on the web, I doubt one is built in.

                  Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  E 1 Reply Last reply
                  0
                  • C Christian Graus

                    not sure in js. I would expect you'd find one on the web, I doubt one is built in.

                    Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                    E Offline
                    E Offline
                    engsrini
                    wrote on last edited by
                    #9

                    Ok i got this function from web and it worked

                    var encodedHtml = escape(NewsBody_rich.document.body.innerHTML);
                    encodedHtml = encodedHtml.replace(/\//g,"%2F");
                    encodedHtml = encodedHtml.replace(/\?/g,"%3F");
                    encodedHtml = encodedHtml.replace(/=/g,"%3D");
                    encodedHtml = encodedHtml.replace(/&/g,"%26");
                    encodedHtml = encodedHtml.replace(/@/g,"%40");

                    I was thinking about another way to pass the data to server using hidden textbox I thought of putting the formatted html message to a asp hidden textbox and take it in the code-behind using the following script

                    document.getElementById("TextBox1").value=NewsBody_rich.document.body.innerHTML;

                    but this not working, when i put alert after this script code it shows the TextBox1.Value as assigned html message, but when i debug in the code-behind the TextBox1.Text value is empty. i dont know why?! i did lot of debugging still couldnt able to find, i even replace asp server textbox with html server texbox, still not working!! Do you have any idea why is it so!? Thanks SRini

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups