在JavaScript代码中包含SSI [英] include SSI in javascript code

查看:98
本文介绍了在JavaScript代码中包含SSI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于查询字符串,我在页脚页面中包含了一部分不同的代码SSI. 我的查询字符串例如:

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=520&genderType=2

?headId = 600& genderType = 1

?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"-->')
    };

});

有人可以帮助我吗?

谢谢!

推荐答案

您可以将SSI放在html页面中,例如anotherpage.html

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

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

然后使用javascript加载页面:

Then load the page using javascript:

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

这篇关于在JavaScript代码中包含SSI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆