0

I'm working on a PHP assignment and having trouble getting an ajax call to properly redraw. Everything almost works except I have this one line of code that keeps giving me errors:

$line .= '<input type="button" onclick="$j(this).attr(\'disabled\',true).val(\'Updating...\');xajax_save_message(' . $error . ',' . '$j(\'#error_' . $error_code . '\').val());return false;" id="save_button_' . $error_code . '" value="Save" />';

I think I have an escape character in the wrong place. Currently, the error message that I'm getting is:

XML Parsing Error: not well-formed
Location: http://127.0.0.1/dev/admin_eprescribing_error_messages.php
Line Number 1, Column 63:

The error occurs when I actually push the button to save. As I said, this is a PHP project which uses a library called Xajax to do ajax calls.

Any help would be great.

$j = "$"."j";
    $line .= '<td align="left">';
    $line.= <<<DELIMETER
    <input type="button" onclick="$j(this).attr('disabled',true).val('Updating...');xajax_save_message({$error_code},$j('#error_message{$error_code}').val());return false;" id="save_button_{$error_code}" value="Save" />;
    DELIMETER;
    $line .= '&nbsp';

5
  • is this error showing right after document load? Commented Nov 13, 2020 at 14:38
  • No the error is showing when I go to push the save button in the above line of code. I feel fairly certain that I'm have a misplaced ' or " or \ Commented Nov 13, 2020 at 14:49
  • xajax_save_message(' . $error . ',, unless $error is numeric, you need to quote that string: xajax_save_message(\'' . $error . '\', Commented Nov 13, 2020 at 15:29
  • I added that and I almost got there but now have a Uncaught SyntaxError: private fields are not currently supported this never ends. Back to seeing what that issue is! Commented Nov 13, 2020 at 15:47
  • okay I have an extra ' before the jquery call and not sure how to get rid of it - I'm terrible with escaping characters: message(\'' . $error . '\', \'' . '$j(\'#error_message_' . $error_code . '\') Commented Nov 13, 2020 at 15:53

1 Answer 1

0

You should use

$j = "$"."j";
$line.= <<<DELIMETER
<input type="button" onclick="$j(this).attr('disabled',true).val('Updating...');xajax_save_message({$error},$j('#error_{$error_code}).val());return false;" id="save_button_{$error_code}" value="Save" />;
DELIMETER;
Sign up to request clarification or add additional context in comments.

9 Comments

Thank you - I think I'm almost there but I get this error message: Uncaught SyntaxError: expected expression, got ',' => is there something that is left out? I'll be reviewing as well and thank you again
Thank you again - that got rid of all the errors but now the button disappears when pressed - that's not what I want but I think this is so close - I've updated my initial question to show you what I have -please note that the variable names slightly changed but that should not matter.
can you tell me which library you are using
That's a good question - this is an application that I just started to work on and I know it's PHP 7.4 and uses Xajax sorry I could not be more helpful.
I tested this on my side I think the issue must be in xajax_save_message()
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.