2013-02-22 97 views
0
<script type="text/javascript"> 
$(document).ready(function() { 
    showHome(); 
}); 

function findTemplate() { 
var selectedIndustry = $("#industrySelected option:selected").text(); 
var selectedTemplate =$("#templateCode").val(); 
$.ajax({ 
    type: "post", 
    url: "/_layouts/TBSharePointProject/SharePointTestService.asmx/redirectUserToAppropriateTemplate", 
    contentType: "application/x-www-form-urlencoded", 
    dataType: "xml", 
    data: { industry: selectedIndustry, templateCode: selectedTemplate, checkList: "" }, 
    success: function (result) { 
     xmlStr = xmlToString(result); 
     xml = removeFirstAndLastLine(xmlStr) 
     myJsonObject = xml2json.parser(xml); 
     //alert(myJsonObject.eccn[0].eccnno); 

     $("#surveyScreen").empty(); 
     for(var i = 0; i <= myJsonObject.eccn.length; i++) { 

      $("#surveyScreen").append("<p><input id='" + myJsonObject.eccn[i].guid + "' type='checkbox' checked ='checked'>" + myJsonObject.eccn[i].eccnno + ": " + myJsonObject.eccn[i].title + "</input></p>"); 

     } 
     $("#surveyScreen").append("<br/><input type='button' id='goHome' value='Back'  onclick =\"javascript: showHome();\"/>"); 
    }, 
    error: function (result) { 
     alert('error occured'); 
    }, 
    async: true 
}); 


} 
//Converst xmlString to String 
function xmlToString(xmlObj) { 
if (navigator.appName == "Netscape") { 
    return (new XMLSerializer()).serializeToString(xmlObj); 
} 
if (navigator.appName == "Microsoft Internet Explorer") { 
    return xmlObj.xml; 
} 
} 

function removeFirstAndLastLine(xmlStr) { 
// break the textblock into an array of lines 
var lines = xmlStr.split('\n'); 
// remove one line, starting at the first position 
lines.splice(0, 2); 
// join the array back into a single string 
var newtext = lines.join('\n'); 
//Removes the last line 
if (newtext.lastIndexOf("\n") > 0) { 
    return newtext.substring(0, newtext.lastIndexOf("\n")); 
} else { 
    return newtext; 
} 
} 

function showHome() { 

$("#surveyScreen").empty(); 
$("#surveyScreen").append("<p>Do you have a saved checklist?</p>"); 
$("#surveyScreen").append("<p>Submission Code:<input type='text' id='checkListCode'/> </p>"); 
$("#surveyScreen").append("<p><input type='button' id='getCheckList' value='Get Saved  Checklist' onclick =\"javascript: findTemplate();\"/></p><br/><br/>"); 
$("#surveyScreen").append("<p>Industry</p>"); 
$("#surveyScreen").append("<select id='industrySelected'>"+ 
          "<option>Computer & Networking</option>"+ 
          "<option>Biotechnology</option>"+ 
          "Industry</select>"); 
$("#surveyScreen").append("<br/>Or"); 
$("#surveyScreen").append("<p>Template Code:<input type='text' id='templateCode'/> </p>"); 
$("#surveyScreen").append("<p><input type='button' id='getTemplate' value='Next'  onclick =\"javascript: findTemplate();\"/></p><br/><br/>"); 

} 

</script> 
<body> 
<div id="surveyScreen"> 
</div> 
</body> 

工作有人能向我解釋爲什麼這個函數調用在Firefox而不是IE瀏覽器,並需要做它在IE瀏覽器的東西。JavaScript函數在IE瀏覽器不工作,但在Firefox

所以我更新了帖子,以顯示更多的我code..some件冷落......和其他一些不重要

+0

請添加一些您的標記。它的作品在我的IE – 2013-02-22 16:14:16

+0

「surveyScreen」是什麼類型的元素? – undefined 2013-02-22 16:14:22

+0

@undefined它不是一個元素,它是一個元素的id。 – 2013-02-22 16:15:08

回答

3

IE是當它涉及到重複的ID多挑剔。 ids應該(當然)是唯一的,但firefox只是抓住第一個並繼續。 IE瀏覽器忽略嘗試訪問Dupe ID。

你沒有發佈你的HTML,但這是我首先看的方向。

+0

這是一個測試: http://jsfiddle.net/cZTys/1/ – 2013-02-22 16:24:16

0

確保在調用這行代碼之前,不要錯過任何地方的分號。我發現一個缺少的分號(或任何其他錯誤)將導致IE停止在錯誤的地方工作,但它仍然在FF中工作。

您的代碼在IE 9工作正常http://jsfiddle.net/eL2nU/

$("#surveyScreen").append("<p><input type='button' id='getTemplate' value='Next' onclick=\"javascript: findTemplate();\"/></p><br/><br/>"); 
相關問題