javascript - How to insert a variable inside a json url? -
i trying use defined var inside json url:
var articlename = "test"; $.getjson( "https://www.googleapis.com/customsearch/v1?key=api_my&cx=cx_my&q='+articlename+'&searchtype=image&filetype=jpg&imgsize=xlarge&alt=json`",
i tried: q='+articlename+'
it's wrong
just use "
before , after +
, &q='"+articlename+"'&
another solution using data
option 1: article name
$.getjson("https://www.googleapis.com/customsearch/v1?key=api_my&cx=cx_my&searchtype=image&filetype=jpg&imgsize=xlarge&alt=json",{ "q":articlename },
option 2: param
$.getjson("https://www.googleapis.com/customsearch/v1",{ "q" : articlename, "alt" : "json", "imgsize" : "xlarge", "filetype" : "jpg", "searchtype" : "image", "cx" : "cx_my", "key" : "api_my" },
Comments
Post a Comment