Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I hit my database with an AJAX call using javascript?
    primarykey
    data
    text
    <p>I am pretty new at this stuff, so bear with me.</p> <p>I am using ASP.NET MVC.</p> <p>I have created an overlay to cover the page when someone clicks a button corresponding to a certain database entry. Because of this, ALL of my code for this functionality is in a .js file contained within my project.</p> <p>What I need to do is pull the info corresponding to my entry from the database itself using an AJAX call, and place that into my textboxes. Then, after the end-user has made the desired changes, I need to update that entry's values to match the input. I've been surfing the web for a while, and have failed to find an example that fits my needs effectively.</p> <p>Here is my code in my javascript file thus far:</p> <pre><code>function editOverlay(picId) { //pull up an overlay $('body').append('&lt;div class="overlay" /&gt;'); var $overlayClass = $('.overlay'); $overlayClass.append('&lt;div class="dataModal" /&gt;'); var $data = $('.dataModal'); overlaySetup($overlayClass, $data); //set up form $data.append('&lt;h1&gt;Edit Picture&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;'); $data.append('Picture name: &amp;nbsp;'); $data.append('&lt;input class="picName" /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'); $data.append('Relative url: &amp;nbsp;'); $data.append('&lt;input class="picRelURL" /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'); $data.append('Description: &amp;nbsp;'); $data.append('&lt;textarea class="picDescription" /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'); var $nameBox = $('.picName'); var $urlBox = $('.picRelURL'); var $descBox = $('.picDescription'); var pic = null; //this is where I need to pull the actual object from the db //var imgList = for (var temp in imgList) { if (temp.Id == picId) { pic= temp; } } /* $nameBox.attr('value', pic.Name); $urlBox.attr('value', pic.RelativeURL); $descBox.attr('value', pic.Description); */ //close buttons $data.append('&lt;input type="button" value="Save Changes" class="saveButton" /&gt;'); $data.append('&lt;input type="button" value="Cancel" class="cancelButton" /&gt;'); $('.saveButton').click(function() { /* pic.Name = $nameBox.attr('value'); pic.RelativeURL = $urlBox.attr('value'); pic.Description = $descBox.attr('value'); */ //make a call to my Save() method in my repository CloseOverlay(); }); $('.cancelButton').click(function() { CloseOverlay(); }); } </code></pre> <p>The stuff I have commented out is what I need to accomplish and/or is not available until prior issues are resolved.</p> <p>Any and all advice is appreciated! Remember, I am VERY new to this stuff (two weeks, to be exact) and will probably need highly explicit instructions.</p> <p>BTW: overlaySetup() and CloseOverlay() are functions I have living someplace else.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload