Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
function enterword() {
	$.ajax({
		type: 'POST',
		url: '/xxx/postme/',
		data: 'word='+$('#word').val()+'&r='+(new Date().getTime()),
		success: function(html) {
			if (html == 'error') {
				$('#entererror').show()
				//setTimeout('window.location="/xxx/sss/"', 3000)
				window.location="/fff/fff/"
			} else
				$('#forajax').html(html)
		}
	})
}


How from c# call this funcrion
Posted
Updated 31-Jul-12 22:23pm
v2
Comments
Ankur\m/ 1-Aug-12 4:55am    
You cannot call it from server side, you can register it to be called after the page is loaded / at some event on the client side though. In case of ASP.NET, you will need a page method called postme. If you are using MVC you we need a Controller Action method named postme.
I am not very sure, what exactly you are looking for.

the function is "enterword()", its a usual javascript function, the $.ajax is part of the jQuery UI, which needs to be referenced.
to call the function from "c#" (i am guessing that you mean "ASP.NET") you simply need to write "enterword();" to the appropriate attribute.
Here is an example:
ASP.NET
<asp:button Id="myId" Text="click me" onClientClick="enterword(); return false;" />


Here is an HTML Example:
HTML
<input type="Button" value="click me" id="myId"  onclick="enterword(); return false;" />


the "return false;" is mostly obsolete but i still use it, it overrides the defaultbehaviour of the browser after the javascript is executed.
 
Share this answer
 
v3
Comments
[no name] 1-Aug-12 4:20am    
no asp.net) i use c#. I authorised on site and want send post request with ajax function
[no name] 1-Aug-12 4:22am    
excuse. java script function
efkah 1-Aug-12 7:16am    
In this case, try googling for how to implement WebService in C#
In shorT: In References, Add WebReference, Intiate it and use it.
http://msdn.microsoft.com/en-us/library/6h0yh8f9%28v=vs.80%29.aspx
C#
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript",
   "javascript:TestJavascriptFunction();", true);
 
Share this answer
 
Comments
[no name] 1-Aug-12 5:59am    
no ASP.net!! simply c#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900