Solved

Javascript to update an MSSQL record without reloading the web page

Posted on 2014-07-30
4
294 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 100 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 400 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 110

Expert Comment

by:Ray Paseur
ID: 40229012
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
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)

733 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