开发者

ajax call does not fire jquery code

开发者 https://www.devze.com 2023-01-31 05:56 出处:网络
Hi In my script I am trying to call a page through ajax and then insert the contents of that page in the dom. The target page has this code:

Hi In my script I am trying to call a page through ajax and then insert the contents of that page in the dom. The target page has this code:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="js/highcharts.js" type="text/javascript"></script>
<script type="text/javascript">
var chart1; // globally available
$(document).ready(function() {
  chart1 = new Highcharts.Chart({
     chart: {
        renderTo: 'chart-container-1',
        defaultSeriesType: 'bar'
     },
     title: {
        text: 'Fruit Consumption'
     },
     xAxis: {
        categories: ['Apples', 'Bananas', 'Oranges']
     },
     yAxis: {
        title: {
           text: 'Fruit eaten'
        }
     },
     series: [{
        name: 'Jane',
        data: [1, 0, 4]
     }, {
        name: 'John',
        data: [5, 7, 3]
     }]
  });
});
</script>
</head>
<div id="chart-container-1" style="width: 100%; height: 400px"></div>

It is from highcharts script. When I make the ajax call I just get an empty div. Nonetheless when I run the page without the ajax call it runs just fine.

EDIT: The page I am requesting contain jquery script, however I not using jquery script to call it. I am using these functions instead:

function callAHAH(url, pageElement, callMessage, errorMessage) {
 document.getElementById(pageElement).innerHTML = callMessage;
 try {
 req = new XMLHttpRequest(); /* e.g. Firefox */
 } catch(e) {
   try {
   req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
   } catch (e) {
     try {
     req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
     } catch (E) {
      req = false;
     } 
   } 
 }
 req.onreadystatechange = function() {responseAHAH(pageElement, callMessage, errorMessage);};
 req.open("GET",url,true);
 req.send(null);
}

function responseAHAH(pageElemen开发者_如何学Ct, callMessage, errorMessage) {
var output = '';
if(req.readyState == 4) {
  if(req.status == 200) {
     output = req.responseText;
     document.getElementById(pageElement).innerHTML = output;
     } else {
     document.getElementById(pageElement).innerHTML = errorMessage+"\n"+output;
     }
  }
}


jQuery AJAX calls strip script tags out of the response unless you have set the datatype option to "html"

Make sure you have set the datatype to html.

$.ajax({url:"/sompage.html",datatype:"html",type:"GET"});

See the documentation here


if u use update panel

Sys.Application.add_load(your_function);
0

精彩评论

暂无评论...
验证码 换一张
取 消