jQuery Ajax CGI: load script -


i trying load perl cgi script's content html page. .load() not work. please tell me what's wrong here:

$(document).ready(function() {   $('input:checkbox').change(function() {     var nom = $(this).attr("value");     if ($(this).is(':checked')) {       alert('okok');       $('body').load("../cgi-bin/essai.pl");     } else {       //$("#" + nom).remove();     }   }); 

i like:

  • when check checkbox (which has value "toto") load (in ajax) essai.pl?param=toto
  • when uncheck checkbox, remove content loaded before.

hope has little time me leave jquery nightmare.
bye.

you're loading script's output directly body, hence make previous body content (including checkbox(es)) disappear. assume experience.

what should have dedicated block script generated content, , use block target of load function.

html:

<body> <div id="controller">   <input type="checkbox" name="toto" id="toto"></input> load / unload content   </div> <div id="target">   content comes here   </div> </body> 

javascript:

$('input:checkbox').change(function(){     if ( $(this).is(':checked') ) {       var target_url = "../cgi-bin/essai.pl?param="+$(this).attr('name');       $('div#target').load(target_url);     }     else {       $("div#target").html('');     } }); 

i refrain "../cgi-bin/" type relative path definition , use absolute path instead.

working example available @ http://jsbin.com/izuni4/19

edit seems didn't grasp trying achieve. here edited version of same javascript appends/removes content blocks triggered multiple checkboxes. hope solves issue:

http://jsbin.com/izuni4/22/


Comments