Masking & For AJAX Requests
Solution 1:
Alternatively, you could assign the onclick in your JavaScript. This is better because it keeps your markup cleaner. Here's a jquery solution.
$('a').bind('click', function() {
start_ajax_request('url.php?key1=val1&key2=val2&key3=val3');
});
Solution 2:
Try passing with the JS escape() function and by passing the ampersand as %26 The same way I am sure you see spaces passed as %20
Hope it works
Solution 3:
You should use the encodeURIComponent() function to send the URL string and then decode it in the reciever. If you're using PHP, you need to do something like this:
utf8_decode(rawurldecode(str));
Solution 4:
I'm not an expert and i don't know if my answer is exactly related to your question.
I was having a similar problem, but in the oposite direction, i noticed that when i created an onclick event with parameters received via ajax in json format, parsed and placed in the document, when i viewed the source code i got something like
<a href="#" onclick="qString('blah.php', 'ipp=2&ord=0');">blah</a>
but that didn't stop the app from working, and i never had a problem before because i dont use & as part of a parameter value, and if the value is user input i use encodeURIComponent to encode the value.
So i went on and discarted any json parse issues or ut8 related issues, thats when i realized that when using javascript inside html having & amp; instead of & is actually correct.
So in my case what i thought for a moment was not ok, is ok for the W3C valitador.
Try:
<html>
<head>
<title>Test</title>
<script language="javascript">
function foo(url) {
alert(url.indexOf('&'));
alert(url.indexOf('&'));
return false;
}
</script>
</head>
<body>
<a href="#" onclick="foo('url.php?key1=val1&key2=val2&key3=val3');">Test</a>
</body>
</html>
Post a Comment for "Masking & For AJAX Requests"