Solved

Javascript to update an MSSQL record without reloading the web page

Posted on 2014-07-30
4
284 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
4 Comments
 
LVL 74

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 108

Expert Comment

by:Ray Paseur
ID: 40229012
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now