Question

I have copy/paste a script from a Bing basic tutorial over here: Bing basic API

I have paste the example script in dreamweaver:

<script type="text/javascript">
function search() {
var search = "&query=" + document.getElementById("searchText").value;
var fullUri = serviceURI + AppId + search;
var head = document.getElementsByTagName('head');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = fullUri;
head[0].appendChild(script);
}
function searchDone(results) {
var result = null;
var parent = document.getElementById('resultList');
parent.innerHTML = '';
var child = null;
for (var i = 0; i < results.SearchResponse.Image.Results.length; i++) {
result = results.SearchResponse.Image.Results[i];
child = document.createElement('li');
child.className = "resultlistitem";
child.innerHTML = '<a href="' + result.Url +'"><img src="' +
result.Thumbnail.Url +'" alt="' + result.Title +'" /></a>';
parent.appendChild(child);
}
}
var AppId = "&Appid=86F7F70727A6D88CCE422ED44905A378E9780D81";
var serviceURI = "http://api.bing.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sourc
es=image";

</script>

Dreamweaver is telling me something is wrong over here:

var serviceURI = "http://api.bing.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sourc
    es=image";

I also put the script on JsBin for debugging but Jsbin is telling me the script is fine..I have no idea what the problem could be becouse the script doesnt work in the browser

Was it helpful?

Solution

Based on the code that you posted, it appears that Dreamweaver is correct. When you want to wrap a string to a second line in JavaScript, you need to do one of two things:

var serviceURI = "http://api.bing.net/json.aspx?sonType=callback&JsonCallback" + 
"=searchDone&source=image";

Or

var serviceURI = "http://api.bing.net/json.aspx?sonType=callback&JsonCallback \
=searchDone&source=image";

Here's a working fiddle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top