This is not possible — with the provided example-string or anything similar.
\x
is the first problem here. JavaScript thinks this is a Hexadecimal escape sequence, that's why the JavaScript-Interpreter is throwing an appropriate error:
Uncaught SyntaxError: Invalid hexadecimal escape sequence
And even if we take another example string: 'http:\\www.xyz.com\yy\ab\1324\1324.jpg'
it will fail.
JavaScript thinks that the backslashes are there to escape something as Octal escape sequence — that is why just entering this string into a JS-Console and hitting return gives you back:
"http:\www.xyz.comyyabZ4Z4.jpg"
To visualize it even more, enter into your console: 'http:\\www.xyz.com\yy\ab\1324\1324.jpg'.split('');
You'll see that even \132
gets converted to Z
.
I tried many things right now, like replacing/escaping, trying JSON.stringify, using a text-node, using CDATA inside a virtual XML-document, etc. etc. – nothing worked. If somebody finds a JavaScript-way for doing this, I'd be happy to know about it!
Conclusion
I don't know of any way for doing this inside JavaScript. There seems to be no chance.
Your only solution as I see it, is to escape it on the server-side.
In your case you will have to write a little server-script, that calls your used API and converts/escapes everything to be ready for your JS. And your JS calls this little server-script.