我遇到了一些麻煩,我認為我的語法和結構是正確的,但由于某種原因,函式失敗了。
products.php 頁面
我在頁面底部有這個函式,它獲取 $child 的值并將其添加到頁面,在那里它被傳遞給 Javascript 函式get_child_options:
jQuery(document).ready(function(){
get_child_options(<?=$child;?>);
});
該功能get_child_options由我的footer.php頁面添加
頁腳.php
function get_child_options(selected){
if(typeof selected === 'undefined'){
var selected = '';
}
var parentID = jQuery('#parent').val();
$.ajax({
url: '/admin/parsers/child_categories.php',
type: 'POST',
data: {parentID: parentID, selected: selected},
success: function (data){
jQuery('#child').html(data);
},
error: function(){alert("Something went wrong with the child options.")},
});
}
jQuery('select[name="parent"]').change(get_child_options);
當我加載 products.php 時的錯誤是 get_child_options 沒有宣告我已經在線查看并通過這個論壇,我認為我的 products.php 頁面中我的函式的構成是正確的,我只是不明白為什么它不能識別該函式在我的 footer.php 中宣告并處理該函式。
要補充一點,我已經在我的 products.php 頁面上的函式中嘗試了這個,但我擺脫了未定義的錯誤,但該函式沒有將任何資料傳遞給我的 get_child_options 函式。
jQuery(document).ready(function(){
function getchild(child){
var child = <?=$child;?>
get_child_options(child);
}
});
如果有人可以提供幫助,那就太好了,我想不出我做錯了什么。TIA
我已查看如何通過 JavaScript 呼叫 PHP 函式?并覺得我的情況與那里不同。
uj5u.com熱心網友回復:
我發現了問題,我的決議器檔案看不到我的身份驗證檔案來獲取該功能。一旦我將正確的路徑添加到檔案中,它就一切正常了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/478366.html
標籤:javascript php html 功能 变量
上一篇:如何用jq變數做雙重間接?
