jquery .load not working

Hi,

I'm wondering why this (jQuery) bit of code isn't working:
(shown in the code snippet)

This code works fine which is just regular ajax (i.e. not using jquery):
   1. function revDescr(condition_id, rev_cat_id) {  
   2.     this.condition_id = condition_id;  
   3.     this.rev_cat_id = rev_cat_id;  
   4.  
   5.     //update the reverse entry description  
   6.     xmlhttp10=GetXmlHttpObject(); //if xmlhttp object not created  
   7.     if (xmlhttp10==null) {  
   8.         alert ("Browser does not support HTTP Request");  
   9.         return;  
  10.     }  
  11.  
  12.     var url="./include_ajax/updateRevDescrSi.php";  
  13.     url=url+"?condition_id="+this.condition_id;  
  14.     url=url+"&rev_cat_id="+this.rev_cat_id;  
  15.     url=url+"&sid="+Math.random();  
  16.     xmlhttp10.open("GET",url,true);  
  17.     xmlhttp10.onreadystatechange=stateChangedRevDescr;  
  18.  
  19.     xmlhttp10.send(null);  
  20. }  
  21.  
  22. function stateChangedRevDescr() {  
  23.     if (xmlhttp10.readyState==4) {  
  24.         var data = xmlhttp10.responseText;  
  25.         document.getElementById("reverse_content").innerHTML = data;  
  26.     } else  {  
  27.         document.getElementById("reverse_content").innerHTML = "Please wait...updating";  
  28.     }  
  29. }  

I've displayed the code in it's beautified format on my blog here and if you wish to copy without the lines:
http://blog.tutorialref.com/javascript-tutorial/jquery-ajax-load-not-working-182.html

Thank you,
vkimura
function revDescr(condition_id, rev_cat_id) {
    this.condition_id = condition_id;
    this.rev_cat_id = rev_cat_id;
    
    var pars = 'condition_id='+this.condition_id+'&rev_cat_id='+this.rev_cat_id; //used by jQuery
    $("#reverse_content").load("updateRevDescrSi.php?"+pars);
 }

Open in new window

Victor KimuraSEO, Web DeveloperAsked:
Who is Participating?
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
I just figured out that my relative url reference was wrong. So I changed that line to:

 $("#reverse_content").load("./include_ajax/updateRevDescrSi.php?"+pars);
0
 
hieloCommented:
the element with id='reverse_content' will need to have innerHTML support if the updateRevDescrSi.php is returning HTML content. What elemeint has  id='reverse_content'?
0
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
Hi hielo,

I think this was a similar problem to the other post. I was using block-level <p> tags and as you said IE doesn't allow other block-level tags. However, I'm wondering if I had to place elements within <select> or <option> via ajax or jquery .load. How would I make it work?

Thanks,
Victor
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Victor KimuraSEO, Web DeveloperAuthor Commented:
Actually, I just test the jquery .load and it doesn't work even when I changed the <p> tag to a <div> tag. The pars are being passed both in IE and firefox as I viewed them in their respective debuggers.
0
 
hieloCommented:
>>However, I'm wondering if I had to place elements within <select> or <option> via ajax or jquery .load. How would I make it work?
I typically designate a container span OR div and have the complete HTML markup for the list (<SELECT...>...</SELECT>) returned as the responseText and then insert that in the span or div (depending on what I chose as the container element) using .innerHTML

>>Actually, I just test the jquery .load and it doesn't work even when I changed the <p> tag to a <div> tag. The pars are being passed both in IE and firefox as I viewed them in their respective debuggers.
Where's your  page/url?
0
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
Here are the pages:

This link uses regular AJAX javascript (i.e. not jQuery):
http://cosmeticguide.com/dev_3/reverse_otc.php

This link (which is a striped down version of the first) uses jQuery but the data isn't displaying in both IE and firefox:
http://cosmeticguide.com/dev_3/reverse_otc2.php

Thank you,
vkimura
0
 
Steve KrileCommented:
Without testing, I'm not sure this will be helpful to you, but I've learned the hard way that concatenating strings INLINE with jquery leads to unexpected results - that is, in some circumstances the code works and others it doesn't.

Have you:

1.  Tested .load() with a simple example like:  
      $("#reverse_content").load("test.html");

Where test.html is some very simple content.

2. Tested .load() with a fully concatenated version of your URL

    var pars = 'updateRevDescrSi.php?condition_id='+this.condition_id+'&rev_cat_id='+this.rev_cat_id;
    $("#reverse_content").load(pars);
0
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
Hi skrile,

I have this code as above:

in regards to point (2).

I will test with a simple html page now though.
function revDescr(condition_id, rev_cat_id) {
    this.condition_id = condition_id;
    this.rev_cat_id = rev_cat_id;
    
    var pars = 'condition_id='+this.condition_id+'&rev_cat_id='+this.rev_cat_id; //used by jQuery
    $("#reverse_content").load("updateRevDescrSi.php?"+pars);
 }

Open in new window

0
 
Steve KrileCommented:
My point is, this code may not work:

$("#reverse_content").load("updateRevDescrSi.php?"+pars);


Because the "+pars" part may not be correctly parsed in jquery.

So, feed the .load() function the fully prepared URL like this:

    var pars = 'updateRevDescrSi.php?condition_id='+this.condition_id+'&rev_cat_id='+this.rev_cat_id;
    $("#reverse_content").load(pars);
0
 
Victor KimuraSEO, Web DeveloperAuthor Commented:
To skrile:
Oh, I see. Okay, good to know. I will try that in the future when I encounter a problem. Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.