rob.m rob.m - 6 months ago 32
Javascript Question

How to insert a variable inside a json url?

I am trying to use my defined var inside the json url:

var articleName = "test";

$.getJSON( "'+articleName+'&searchType=image&fileType=jpg&imgSize=xlarge&alt=json`",

I tried:
but it's wrong


Just use " before and after +, like &q='"+articleName+"'&

Another solution is using data

Option 1: Just for article name


Option 2: All param

    "q"          : articleName,
    "alt"        : "json",
    "imgSize"    : "xlarge",
    "fileType"   : "jpg",
    "searchType" : "image",
    "cx"         : "CX_MY",
    "key"        : "API_MY"