问题
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