How to pass data from client to server in AJAX
-
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
-
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
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
-
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
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 )
-
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
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 )
-
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 )
Ok, Thanks Christian G
Parwej Ahamad R & D with IIS 5.0/6.0
-
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 )
-
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
-
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
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 )
-
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 )
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