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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -