include SSI in javascript code

僤鯓⒐⒋嵵緔 提交于 2020-01-16 19:14:10

问题


based on the query string, I include a portion of a different code SSI in the footer page. My query string for example:

?headId=520&genderType=2

?headId=600&genderType=1

function GetQueryStringParams(sParam){

    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) {
            return sParameterName[1];
        }
    }
}​

$(document).ready(function() {

    var genderM = GetQueryStringParams('genderType');
    var genderF = GetQueryStringParams('genderType');

    if ( genderM == 2 ) {
        $('#adv').html('<!--#include virtual="genderM.shtml"-->')
    } else if (genderF == 1 ){
        $('#adv').html('<!--#include virtual="genderF.shtml"-->')
    };

});

Can someone help me?

Thanks!!


回答1:


You can just put the SSI inside an html page e.g. anotherpage.html

<!--#include virtual="genderM.shtml"-->

Then load the page using javascript:

$.ajax({
    url: "anotherpage.html",
    success: function(data) {
        $('#adv').html(data);
    },
    dataType: 'html'
});


来源:https://stackoverflow.com/questions/22967893/include-ssi-in-javascript-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!