Hi,
so I have the same problem that gazillions of other users seem to have: I cannot figure out how to rebind an event after an AJAX-call.
I have a page (let's call it "name.php") with an ordinary HTML
- <select name="lastname" onChange="nameChanged(this);">
dropdown. The function nameChanged() itself does an AJAX call (simplified like this):
- function nameChanged(currentElement) {
- // alert ('test');
- $.get('doSomething.php', { 'last_name': currentElement.value },
- function(data){
- document.form.name_repeat.value = data.first_name;
- }, 'json');
- }
This works fine as long as I call the script "name.php" directly. If "name.php" gets called from another script (let's say, "big.php") via AJAX and gets inserted into a DIV, the $.get call no longer works. If I uncomment the alert in line 2, however, THAT works, so the nameChanged()-function fires.
It seems to me that I need to rebind the $.get-call somehow, but to what? And how?
I don't understand how global jQuery-calls like this work, I think. It seems to me that this $.get call should fire whenever it is encountered and is not bound to anything. Am I wrong?
Thank you for your help,
Matthias