php cross-domain error - need to replace string? -
i'm using php script pass json data domain javascript file. code works fine responses. however, in few cases there longer values lines broken "\r\n\r\n", , in cases error when try parse results. think maybe "\r\n\r\n" causing error, , hoping replace string space in php script before passing on javascript, i'm not sure how - i'm newbie.
php script:
echo "var forecast='";
include('http://ws1.airnowgateway.org/gatewaywebservicerest/gateway.svc/forecastbyzipcode?zipcode=' . $zipcode . '&format=json&key=[mykey]');
echo "';";
javascript code:
$(document).ready(function() {
$.get(url, function(data) {
mydata = json.parse(forecast);
... etc.
i hoping use str_replace within php script, know i've set wrong, because it's replacing within url itself, not response data:
echo "var forecast='";
include(str_replace("\r\n"," ","http://ws1.airnowgateway.org/gatewaywebservicerest/gateway.svc/forecastbyzipcode?zipcode=" . $zipcode . "&format=json&key=[mykey]"));
echo "';";
am on right track?
the issue include echos out result of call url. try using file_get_contents
:
echo "var forecast='"; $res = file_get_contents("http://ws1.airnowgateway.org/gatewaywebservicerest/gateway.svc/forecastbyzipcode?zipcode=" . $zipcode . "&format=json&key=[mykey]"); echo str_replace("\r\n",$res); echo "';";
Comments
Post a Comment