簡體   English   中英

使用ajax從mysql檢索數據並填充輸入字段

[英]Retrieve data from mysql using ajax and populate input fields

我的頁面上有很多輸入字段。 我正在使用Jquery使用以下數據立即獲取表單的所有值:$(“#profile”)。serialize()。

由於我的MySQL列與輸入字段具有相同的名稱。 是否可以從我的數據庫中輕松選擇*並使用jquery / ajax將結果加載到適當的字段中? 也許是示例或鏈接?

謝謝,斯科特

編輯:好的,謝謝您的幫助,但是我仍然迷失了方向,無法正常工作,這是我到目前為止的工作:

<script type="text/javascript">
$(window).load(function(){
$.ajax({
url: "/profile_functions/profile_about_retrieve.php",
type: 'POST',
data: allFormFields,
success: function(){
    //console.log('done');
}
});

jQuery(#profile).find(":input").each(function(key, val) {
fieldName = jQuery(this).attr("name");
if(fieldName != "" && fieldName != undefined) {
    allFormFields[fieldName] = jQuery(this).val();
  }
 });
});
</script>

通過json_encode回顯了我數據庫中的一些測試數據

[{"key":"test","value":"9"}]

和HTML

<form id="profile" method="post">
<input type="text" name="test"
</form>
           jQuery(formId).find(":input").each(function(key, val) {

                fieldName = jQuery(this).attr("name");

                if(fieldName != "" && fieldName != undefined) {
                    allFormFields[fieldName] = jQuery(this).val();
                }
            });

使用allFormFields數組發送到PHP端點

                  $.ajax({
                        url: url,
                        type: 'POST',
                        data: allFormFields,
                        success: function(){
                            console.log('done');
                        }
                    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM