專做系統家具、系統櫃
客製化流暢舒適居家,免費估價規劃
拆除全系列活動百葉窗.防火安全門.氣密隔音窗
堅固耐用.工廠直營.歡迎洽詢

首頁  •  j2h 論壇 • 程式設計討論     • 

[JQuery] jQuery live update php

房東:路人
發表時間:2011-10-22



  1. SELECT * FROM contacts WHERE id = $_SESSION['user_id'] ORDER BY name ASC LIMIT 5





that pulls out all my data and only gives me 5 results.



Now my goal is to have a little button that opens up a model box with jquery (this I can manage on my own) with a form asking the user to input a number then that number will be sent via post or get to $PHP_SELF and update a local variable with the number the user inputed, then that variable will be used to update the database to increase or decrease the LIMIT value.



I have looked all over the web (with google) to look for submitting a form using AJAX but all the examples i've found don't work for me.



When the user submits the number and the sql query is executed and updated for the outputed table to dynamically update according to the new LIMIT value all without ever refreshing the page to the user.



my jquery code is:




JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)



  1. $(document).ready(function(){
  2. $("form#form").submit(function() {
  3. // we want to store the values from the form input box, then send via ajax below
  4. var val = $('input[name=new_value]').attr('value');
  5.  
  6. $.ajax({
  7. type: "post",
  8. url: "process.php",
  9. data: "val="+ val,
  10. cache: false,
  11. success: function(){
  12. $('form#form').hide(function(){$('.success').fadeIn();});
  13. }
  14. });
  15. return false;
  16. });
  17. });






then my php code is:




JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)



  1. $new_val = $_POST['new_val'];
  2.  
  3. $_val = "UPDATE `settings` SET `display_limit` = {$new_val} WHERE `user_id` = {$_SESSION['user_id']}";
  4. mysql_query($_val) or die(mysql_error());
  5. }






and my form is simple:




JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)



  1. <form id="form">
  2. <input type="text" id="new_val" name="new_val" class="text" />
  3. <input type="submit" name="limit" id="submit" />
  4. </form>




 





  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務



  •  共 0 人回應

    姓名:
    佈告內容:
    其他選項: