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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -