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:
This is the updateAgent() JavaScript function:
Problem:
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:
instead of
I researched about issues regarding the passing of JS variable to Ajax and did some tests but still the problem persists.
Thanks in advance!
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;}"));
This is the updateAgent() JavaScript function:
function updateAgent(id) { var update_id; update_id = '?r=site/updateuser&id='+id; <?php echo CHtml::ajax(array( 'url'=>'js:update_id', 'data'=> "js:$(this).serialize()", 'type'=>'post', 'dataType'=>'json', 'success'=>"function(data) { if (data.status == 'failure') { $('#dialogUpdateAgent div.divForForm2').html(data.div); $('#dialogUpdateAgent div.divForForm2 form').submit(updateAgent); } else { $('#dialogUpdateAgent div.divForForm2').html(data.div); } }", )); ?> return false; }
Problem:
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.
Thanks in advance!