Answered by:
ajax return data results

Question
-
User-1997257017 posted
In a vb.net 2010 web form application I want to do the following: 1. Create a new ajax web page, 2. Use an ajax method that is called from a javascript function and pass parameters to that page. 3. Return the result from ajax and display an error message to the user.
The purpose of the call is to obtain data from a sql server 2012 database and pass the results back to the javascript function. If an error message is needed, this will be detemined by the results of the call to the database.
Thus can you tell me if the above is possible and show me the code on how to accomplish this goal?
If this solution does not work, can you suggest what would work and showe me the code on how to do what you suggested?
Wednesday, August 24, 2016 4:17 PM
Answers
-
User1724605321 posted
Hi wendy,
The firstly step is you need to use jquery ajax to call server side function in javascript :
http://api.jquery.com/jquery.ajax/
Then in server side function , you could use ADO.NET to access database records . Here is a code sample :
Best Regards,
Nan Yu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 26, 2016 1:22 AM
All replies
-
User1724605321 posted
Hi wendy ,
The purpose of the call is to obtain data from a sql server 2012 database and pass the results back to the javascript functionYou could use Jquery Ajax to call server side function , please refer to below article for details :
http://api.jquery.com/jquery.ajax/
You could use ADO.NET to access the database records :
https://msdn.microsoft.com/en-us/library/dw70f090(v=vs.110).aspx
Best Regards,
Nan Yu
Thursday, August 25, 2016 5:14 AM -
User-1997257017 posted
You mentioned, "You could use ADO.NET to access the database records :". How can a JavaScript function access the sql server database? Can you show me that code?
The link, "https://msdn.microsoft.com/en-us/library/dw70f090(v=vs.110).aspx ", does not show how to call the database from a javascript function.
Thursday, August 25, 2016 3:05 PM -
User1724605321 posted
Hi wendy,
The firstly step is you need to use jquery ajax to call server side function in javascript :
http://api.jquery.com/jquery.ajax/
Then in server side function , you could use ADO.NET to access database records . Here is a code sample :
Best Regards,
Nan Yu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 26, 2016 1:22 AM -
User-1997257017 posted
I am really having a problem trying to get the $ajax call to work. I can not even get to the vb.net code to call the database. I have tried using example code and it has not worked so.
Thus could you give me a better example of the ajax that I need to use? Maybe I am not setting up the sub in the default.apx page correctly. Would you give me more of a specific example on how to accomplish this task?
Friday, August 26, 2016 4:12 PM