Solved

calling controller using JQuery ajax calls

Posted on 2011-03-21
3
594 Views
Last Modified: 2012-05-11
Hi...i have a user control contains  3 textboxes and a button
 added to a aspx page .  When clicked it should make a ajax call to controller and pass data of textboxes and it should return a message....how can i do this
0
Comment
Question by:praveen7k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
chuckalicious earned 500 total points
ID: 35189658
A little bit tricky to comment without seeing an example page, or example content. I'm not familiar with aspx, but assuming you wanted to pass the values back using POST, you could do something like the following:

Textboxes are in format <input type="text" name="field1" value="" /> etc

Basically what I'm doing here is binding a click event to the element of a given ID, in this case your button. I am then setting 3 variables, each with the value of the relative text box (not you may want to correctly escape these depending on content) and then I am performing a jQuery POST to a given URL and passing it 3 value pairs, in the format of <value name>:<value>

There are other things you can do to check that the AJAX query returned a success or error, so I suggest you look at the documentation which is very helpful http://api.jquery.com/jQuery.post/



$(function() {
$("<id of button element>").click(function(){
    //in here you need to build a list of the answers, for example
    var  val1=$("input[name='field1']").val();
    var  val2=$("input[name='field2']").val();
    var  val3=$("input[name='field3']").val();

   //now do a post using jQuery AJAX
	$.post("url of your receiving page", {entered_text1 : val1, entered_text2 : val2, entered_text3 : val3}, function(data){
		if (data.length>0){
			//do something
		} 
	}); 
})
})

Open in new window

0
 

Author Comment

by:praveen7k
ID: 35223654
This was helpful for textboxes.....
In my rek there is third part uploadify control ..so here usercan upload 1o files max..so when i click button it should make a ajax call to controller it should post all these attachments to the controller ...is there any way to do this.....
0
 
LVL 4

Expert Comment

by:chuckalicious
ID: 35230392
I don't think there's an easy way to do Ajax file uploads. I've looked at this for PHP using POST. I would Google AJAX file uploads and see what you get.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question