?
Solved

Javascript to update an MSSQL record without reloading the web page

Posted on 2014-07-30
4
Medium Priority
?
304 Views
Last Modified: 2014-07-30
Hello,

I am looking for a script to update an MSSQL Record when a user clicks a button on a page without reloading the page - is this possible to achieve?

Thanks in advance!
0
Comment
Question by:Nico2011
[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
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 400 total points
ID: 40228941
You need to look into AJAX. You'll still need an endpoint on the server that can accept the async request. How you set this up will depend on what framework you are using to build your site.
0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 1600 total points
ID: 40228944
You would need to use ajax to call a code behind page like asp/php/.net etc
$("#mybutton").click(function() {
    var mydata = $("#mytextfield").val();
    $.ajax({   
       type: 'POST',   
       url: 'update_record.php',   
       data: {mydata:mydata }
    });
  });

Open in new window

In this example you have a button on a form with an ID of mybutton, a text field with an id of mytextfield and a php page with the name of update_record.php which is accepting a form element of mydata.  You would just adjust this accordingly and modify your update_record.php to accept what you need.  Then have that page update your DB.
0
 

Author Closing Comment

by:Nico2011
ID: 40229011
Thank you both.  Thanks for the code too Randy - much appreciated!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40229012
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

777 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