Solved

Javascript to update an MSSQL record without reloading the web page

Posted on 2014-07-30
4
292 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 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 109

Expert Comment

by:Ray Paseur
ID: 40229012
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
Viewers will learn how the fundamental information of how to create a table.

856 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