I have a link that fires an AJAX request inside a JavaScript function that will render a pop-up form. This pop-up form is actually an ‘edit’ form, meaning there is data already filled in each form element.
This is the code for the link:
CHtml::link('Update', "", // the link to open the dialog box
array(
'style'=>'cursor: pointer; text-decoration: underline;',
'onclick'=>"{updateAgent(" . $agent['id'] . "); $('#dialogUpdateAgent').dialog('open');return false;}"));
The form does not seem to submit. And when I check the console in firebug, it causes "NetworkError: 500 Internal Server Error" everytime I hit the submit button of the form with this url: "site/updateuser&id=[object%20Object]".
The form will only submit successfully if I will hard code the id value of the JS function like this:
update_id = '?r=site/updateuser&id='+3;
instead of
update_id = '?r=site/updateuser&id='+id;
I researched about issues regarding the passing of JS variable to Ajax and did some tests but still the problem persists.
When I click a link that will call the JavaScript function updateAgent(id), it runs the Ajax code that is why the data fills in the form perfectly because the function can retrieve the value of ‘id’ directly from the link.
However, whenever I click the submit button, the form will call again the function updateAgent() through this line:
And why are you passing this function as a parameter of submit() ?
I don’t know your need, but when a form is submited why woudl you call again the function that is creating/opening the form… wouldn’t you need to close the form at that point? So maybe create a separate function for that.