rob.m rob.m - 1 year ago 141
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

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download