專業的油漆工程,裝潢設計之首選,室內外油漆粉刷
外牆防水施工等服務,20年經驗有口皆碑
新竹拆除專業鐵工團隊,給你一流品質,鐵皮屋、鐵厝、鋼構屋
免費諮詢、價格合理、免費估價

首頁  •  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 人回應

    姓名:
    佈告內容: