Trouble with jQuery, Ajax, Jsp
I have a small problem: I'm hosting java servlets from JavaScript code below. The servlet works and returns the correct result but not displayed. This is the code in question:
HTML Code:
jQuery (document). ready (function () {
refresh (document.getElementById ( 'elementPere1'). value, 'elementFils1', elementFilsSelected ',' nameServlet ');
});
function refresh (dadId, sonName, selectedName, servletName) {
jQuery.ajax ({
type: "GET", url: "/ path /" + servletName + ". view", data: "dadId =" + dadId, datatype: "xml",
success: function (result) {
var selectedValue = document.getElementById (selectedName +''). value
jQuery ( '#' + sonName). empty ()
jQuery (result). find ( 'item'). each (function () {
id_text var = jQuery (this). find ( 'value'). text ();
name_text var = jQuery (this). find ( 'name'). text ();
if (selectedValue == id_text) {
jQuery ( 'selected=\"selected\" value=\'' <option id_text + +'\'>' name_text + + '</ option>'). appendTo ( '#' + sonName);
} else {
jQuery ( 'id_text <option value=\'' + +'\'>' name_text + + '</ option>'). appendTo ( '#' + sonName);
}
});
}
});
}
Re: Trouble with jQuery, Ajax, Jsp
The success callback execute there? What version do you use jQuery? Have you watched (with Firebug for example) if an error occurs in JavaScript?
it would seem that "elementFilsSelected" causes an error, it is wrong to copy and paste?
Re: Trouble with jQuery, Ajax, Jsp
Yes function of success in good time. I use jQuery 1.2.6
Using Firebug and alert () everywhere, it seems that the problem appears from:
Code:
id_text var = jQuery (this). find ( 'value'). text ();
When I do a alert (jQuery (this). Find ( 'value'). Text ()); it does not appear.
For elementFilsSelected is indeed an error on my part.
Re: Trouble with jQuery, Ajax, Jsp
On this line here, making a console.dir (this) with Firebug to see what is returned, because I understand what you want to do, you want to display the value of attribute "value", if that is not made with the method find () with attr () (at least in the version 1.3 of jQuery in passing that I advise you).