亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 PHP 中格式化 HTML 下拉列表的 XML 響應

在 PHP 中格式化 HTML 下拉列表的 XML 響應

海綿寶寶撒 2023-03-18 16:15:38
我有一個 javascript onChange 函數,它調用一個 PHP 文件來運行,獲取 UPS 費率,并返回一個帶有費率下拉列表的 HTML 更新。我讓這一切工作得很好,但現在我需要根據比較向選項列表添加一個項目。Java腳本:function fetch_UPS(el){    var zip = el;    if (zip.length !== 5) {        alert ("Please enter a valid 5-digit US zip code.");        return false;    }    else {        var cartID = getCookie('cornerstoreid');        document.getElementById('blackoverlay').style.display = "block";        document.getElementById('pp_checkout').style.display = "none";        $.ajax({            type: 'GET',            cache: false,            url: 'fetch_rates.php',            data: { zip : zip, cartID : cartID },            success: function(response){                var droplist = document.getElementById("shipping_field");                var htmlchange = "<span class=\"cart_opt_label\">Shipping: </span>" + response;                droplist.innerHTML = htmlchange;                document.getElementById('blackoverlay').style.display = "none";                document.getElementById('btn_sub_txt').innerHTML = '<input type="button" id="pp_checkout" value="" onclick="paypal_checkout_submit();" style="display:none;" />Please update shipping to continue';            }        });    }}用于返回的 PHP(在返回之前刪除所有位)if ($response == false) {        throw new Exception ( "Bad data." );    } else {        // save request and response to file        $fw = fopen ( $outputFileName, 'w' );        fwrite ( $fw, $response );        fclose ( $fw );                // Load XML file        $xml = new DOMDocument;        $xml->load($outputFileName);        // Load XSL file        $xsl = new DOMDocument;        $xsl->load('style.xsl');        // Configure the transformer        $proc = new XSLTProcessor;        // Attach the xsl rules        $proc->importStyleSheet($xsl);        echo $proc->transformToXML($xml);    }在測試中,我的IF語句只在返回的末尾添加一個字符串,但是如果我嘗試select從 XSL 中刪除結束標記并將其添加到 PHP 文件中,它會丟棄格式化的返回并且只返回IF陳述。我不做很多編碼,而且由于中間通常有 6 個月到一年的時間,所以我經常落后于當前的編碼要求。我確信我缺少一些 XSL 規則,但我已經嘗試了我能想到的所有搜索組合,但沒有提出任何解決方案。
查看完整描述

1 回答

?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

我想到了。

當我最初刪除最后兩個選項和結束標記時,我留在了SELECTXSL 樣式表中的開始標記中。這導致樣式表失敗,因為它有一個沒有結束標記的開始標記。一旦我SELECT從 XSL 樣式表中刪除了標記行并對 PHP 進行了以下更改,一切都完美無缺。

這是對 PHP 的更改:

$openTag = '<select name="shipping_options" id="shipping_options">';

$closeTag = '<option value=\'8!!!0.00\'>Please call for freight pricing</option>

        <option value=\'9!!!0.00\'>Please call for international pricing</option>

    </select>';


....


else {

        // save request and response to file

        $fw = fopen ( $outputFileName, 'w' );

        fwrite ( $fw, $response );

        fclose ( $fw );

        

        // Load XML file

        $xml = new DOMDocument;

        $xml->load($outputFileName);


        // Load XSL file

        $xsl = new DOMDocument;

        $xsl->load('style.xsl');


        // Configure the transformer

        $proc = new XSLTProcessor;


        // Attach the xsl rules

        $proc->importStyleSheet($xsl);


        echo $openTag;

        echo $proc->transformToXML($xml);

        if ($to_height > 0 && $to_height <= 2) {

            echo $openTag . 'extra text here' . $closeTag;

        }

        else {

            echo $openTag . $closeTag;

        }

    }


查看完整回答
反對 回復 2023-03-18
  • 1 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號