Ciao a tutti ragazzi, ho uno script che mi inserisce dei record in un database tramite una funzione che richiama una pagina ASP
Funzione:
------------------------------------------------------------------------------------------------------
Il mio formcodice:<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { //##### send add record Ajax request to response.php ######### $("#FormSubmit").click(function (e) { e.preventDefault(); if($("#contentText").val()==='') { alert("Non lasciare il campo vuoto"); return false; } $("#FormSubmit").hide(); //hide submit button $("#LoadingImage").show(); //show loading image var myData = 'content_txt='+ $("#contentText").val(); //build a post data structure jQuery.ajax({ type: "POST", // HTTP method POST or GET url: "add-marca.asp", //Where to make Ajax calls dataType:"text", // Data type, HTML, json etc. data:myData, //Form variables success:function(response){ $("#responds").append(response); $("#contentText").val(''); //empty text field on successful $("#FormSubmit").show(); //show submit button $("#LoadingImage").hide(); //hide loading image }, error:function (xhr, ajaxOptions, thrownError){ $("#FormSubmit").show(); //show submit button $("#LoadingImage").hide(); //hide loading image alert(thrownError); } }); }); }); </script>
-----------------------------------------------------------------------------
codice:<select id="responds" class="medium required" name="azienda"> <% StrSql="SELECT titolo FROM tbl_marche ORDER BY titolo ASC" RS.Open StrSql, CN, 1 DO WHILE NOT RS.EOF %> <option value="<%=RS.FIELDS("titolo")%>"><%=RS.FIELDS("titolo")%></option> <% RS.MOVENEXT LOOP RS.CLOSE %> </select> <div class="form_style"> <h3>Aggiungi azienda</h3> <input name="content_txt" id="contentText" placeholder="Scrivi la marca"><br /><br /> <button id="FormSubmit" class="button">Aggiungi marca</button> <img src="images/loading.gif" id="LoadingImage" style="display:none" /> </div>
Pagina che inserisce il record
---------------------------------
codice:<!--#include file="include/inc-connection.asp"--> <% SET RS = Server.CreateObject("ADODB.Recordset") marca=UCASE(Replace(Request.Form("content_txt"), "", "E")) sql = "INSERT INTO tbl_marche ( titolo ) VALUES ('"&marca&"')" cn.execute(sql) StrSql="SELECT titolo FROM tbl_marche ORDER BY titolo ASC" RS.Open StrSql, CN, 1 DO WHILE NOT RS.EOF %> <option value="<%=RS.FIELDS("titolo")%>"><%=RS.FIELDS("titolo")%></option> <% RS.MOVENEXT LOOP RS.CLOSE %>
Problemi riscontrati:
--------------------------------------------------------
Lo script inserisce correttamente il record ma:
1) Non mi prende gli spazi Es: Armani Jeans lo prende come ArmaniJeans, tutto attaccato
2) Quando appendo i risultati della pagina nella select me li ripete ciclandomi sempre la stessa query:
Esempio:
<option value="Armani Jeans">ArmaniJeans</option>
<option value="DonDup">DonDup</option>
<option value="Armani Jeans">ArmaniJeans</option>
<option value="DonDup">DonDup</option>
<option value="Armani Jeans">ArmaniJeans</option>
<option value="DonDup">DonDup</option>
Come posso ovviare questi due problemi?
Qusto script potrebbe esere utile per chi volesse inserire record in database tramite ASP

Rispondi quotando
ehm....sarebbe?

Secondo me se questa domanda la facevi a google ci facevi più bella figura per uno che è del settore
