Skip to main content

Posts

Showing posts with the label jsonp

Is this safe for providing JSONP?

<?php header('content-type: application/json'); $json = json_encode($data); echo isset($_GET['callback']) ? "{$_GET['callback']}($json)" : $json; Or should I for example filter the $_GET['callback'] variable so that it only contains a valid JavaScript function name? If so, what are valid JavaScript function names? Or is not filtering that variable a bit of the point with JSONP? Current solution: Blogged about my current solution at http://www.geekality.net/?p=1021 . In short, for now, I have the following code, which hopefully should be pretty safe: <?php header('content-type: application/json; charset=utf-8'); function is_valid_callback($subject) { $identifier_syntax = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u'; $reserved_words = array('break', 'do', 'instanceof', 'typeof', 'case', 'else', 'new', '

Do myFunction right after JSONP request

I have a script which allows to display Google suggestions: JsFiddle I want to do a function with the first li item rendered by the ui autocomplete, so I did this: $("input#term").keyup(function() { DoMyFunction($('.ui-autocomplete li:first-child a').text(), true); }); The problem however is that there is a period of time between the keyup---> request--->xml cache and html rendering by the ui autocomplete. Which means the my function (DoMyFunction) is being triggered when there is no html list, hence it doesnt work. So my question is: How do I do my function right after the reqeust is cached and processed. Setting a timer wont work because there are to many variables to account for (ea user bandwidth).

Do myFunction right after JSONP request

I have a script which allows to display Google suggestions: JsFiddle I want to do a function with the first li item rendered by the ui autocomplete, so I did this: $("input#term").keyup(function() { DoMyFunction($('.ui-autocomplete li:first-child a').text(), true); }); The problem however is that there is a period of time between the keyup---> request--->xml cache and html rendering by the ui autocomplete. Which means the my function (DoMyFunction) is being triggered when there is no html list, hence it doesnt work. So my question is: How do I do my function right after the reqeust is cached and processed. Setting a timer wont work because there are to many variables to account for (ea user bandwidth).