开发者

Ajaxed javascript code inactive

开发者 https://www.devze.com 2023-04-01 13:07 出处:网络
I have a page on which I am \"ajax-ing in\" a table which has a radio button with the same name on each row. Each row is dynamically generated via a JSTL foreach, but for simplicity I removed it here.

I have a page on which I am "ajax-ing in" a table which has a radio button with the same name on each row. Each row is dynamically generated via a JSTL foreach, but for simplicity I removed it here. Basically, the following is injected on another page via ajax, ohh...I am using jquery 1.8

 <script type="text/javascript">
 $(document).ready(function(){
        if (!$("input[@name='student']:checked").val()) {
            alert('Nothing is checked!');
            return false;
        }
      开发者_高级运维  else {
            alert('One of the radio buttons is checked!');
        }       
 });           
</script>
<table id="studentTable" border="1" style="width: 100%;">
      <tr><th>Select</th></tr>  
      <tr><td><input type="radio" name="student" value="${s.id}"/></td></tr>
</table>

So after the ajax call, using firebug, my script is there in the page along with all of the other table stuff. The thing is the javascript that came accorss via ajax seems to be inactive. I saw some people suggested to use the "eval" function.

Can someone please offer some guidance in this regard, thank you.

EDIT

This is the script I am using to inject the above in my page.

      function search() {
          var resultNode = dojo.byId("results");
          dojo.xhrPost({
              url: "${searchstudentsurl}",
              form: dojo.byId("searchform"),
              load: function(newContent) {
                  dojo.style(resultNode,"display","block");
                  resultNode.innerHTML = newContent;
              },
              error: function() {
                  resultNode.innerHTML = "Your student search form could not be sent";
              }
          });
}

Now dojo has the "handleAs" option, but if i specify the option handleAs: "html", the post simply fails because of this line. I am no sure how to use the dojo eval function. Please Help, thank you.


Documet ready event is triggered only for the main page load, not AJAX calls. Design Javascript logic so that it lies outside HTML and is loaded in a .js file with the main page.

0

精彩评论

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