Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anyone help me, I would like to POST JSON data to the SQL database.
For example, I would like to save the details of the form below in the SQL database:
XML
<form id="formID" class="validate">
        <div data-role="fieldcontain">
        <div class="content-primary">
    <ul data-role="listview" data-inset="true" data-theme="c">
            <li><label for="Name"><em>* </em>Name</label>
            <input data-val="true" data-val-required="The Name field is required." id="Name" name="Name" type="text" value="" />
            <span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
            </li>
            <li><label for="Mobile Number"><em>* </em>Mobile Number:</label>
            <input data-val="true" data-val-required="The Mobile Number field is required." id="Mobile Number" name="Mobile Number" type="text" value="" />
            <span class="field-validation-valid" data-valmsg-for="Mobile Number" data-valmsg-replace="true"></span>
            </li>
           <li><label for="Email"><em>* </em>Email:</label>
            <input data-val="true" data-val-required="The Email Address field  is required." id="Email" name="Email" type="text" value="" />
            <span class="field-validation-valid" data-valmsg-for="Email" data-valmsg-replace="true"></span>
            </li>
             <li><label for="Password"><em>* </em>Password: </label>
            <input data-val="true" data-val-required="The Password field  is Required" id="Password" name="Password" type="text" value="" />
            <span class="field-validation-valid" data-valmsg-for="Password" data-valmsg-replace="true"></span>
            </li>

           <li><label for="ReceiveQuotealertsby"><em>* </em>Receive Quote alerts by :</label><br />
            <label for="flip-c">SMS:</label>
            <select name="slider" id="flip-c" data-role="slider" data-theme="a" class="required">
                <option value="no">No</option>
                <option value="yes">Yes</option>
            </select> <br />

             <label for="flip-c">Email:</label>
            <select name="slider" id="flip-c" data-role="slider" data-theme="a">
                <option value="no">No</option>
                <option value="yes">Yes</option>
            </select>



            </ul>
        </div>

        <div data-role="fieldcontain">

        </div>
        <div class="ui-body">
    <fieldset class="ui-grid-a">
            <div class="ui-block-a"><button type="submit" data-theme="a">Submit</button></div>
            <div class="ui-block-b"><button type="submit" data-theme="c">Cancel</button></div>
              </fieldset>
    </div>
    </ul>
</div>



I would appreciate any help.
Posted
Updated 2-Mar-12 9:36am
v3
Comments
Herman<T>.Instance 2-Mar-12 7:09am    
what have you tried?
Herman<T>.Instance 2-Mar-12 7:10am    
read this
Ed Nutting 2-Mar-12 15:46pm    
Please see my solution - OP is missing fundamental understanding of web protocols/workings i.e. you can't post direct to a database server.
ZurdoDev 2-Mar-12 10:27am    
There is a lot involved. What have you done so far? Look at the jQuery.ajax call to call a webservice or page on your server.
Ed Nutting 2-Mar-12 15:46pm    
Please see my solution - OP is missing fundamental understanding of web protocols/workings i.e. you can't post direct to a database server.

1 solution

Edit: Shifted question text from within pre tags to outside for clarity. In answer to OP's question - what you are trying to do cannot be done directly - you cannot POST data directly to an SQL database - you need a web server in the middle. Try doing this without using AJAX first, then translate it to AJAX. Have a page with one text box and a submit button. Add an event handler to the Click event, then use the System.Data.Linq.DataContext class (look up how to use it on MSDN/Google) to connect and update your database. Then try and make it AJAX

Reason for this (seemingly) obtruse solution: OP clearly doesn't understand how the web protocol really works (which is fair enough) but by going through the steps I have described hopefully OP will realise why what he is trying to do doesn't work directly.

Hope this helps,
Ed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900