//Search for objects and add them to the selection
$(document).ready(function() {
var $search_form = $("form[name='dynamic_query']");
var _api_base_url = "/api/v1/artifact/search/";
var $results = $("#results");
var $pixelator = null;
$search_form.on("submit", function(event) {
event.stopPropagation();
// find the input fields that are contained within the form...
var _api_url = ""; // start with an empty string, and then add the relevant query string attributes and values...
$search_form.find("input").each(function(index, entity) {
var $field = $(entity);
var $name = $field.attr("name"); // as we give our <input> tags the same names as the query string attributes that they populate, we can generate our api call dynamically
var $value = $field.val();
// console.log("form field: name: ", $name, "value: ", $value);
if($value && $value.length > 0) { // make sure the value is non-empty, this should have additional error checking to make sure the string is not just whitespace, etc...
_api_url += ((_api_url.length == 0)?"?":"&") + $name + "=" + encodeURIComponent($value);
}
});
_api_url = _api_base_url + _api_url + ((_api_url.length == 0)?"?":"&") + "limit=5"; // apply an optional limit to our call (sets number of records per page)
// console.log(_api_url);
if(_api_url) {
// call the api via ajax...
$.ajax({
type:"GET",
url:"/static/scripts/ajax/ajax.related_objects.php?url="+encodeURIComponent(_api_url), // we need to use our 'pass through' script to call the api...
dataType:"json",
success:function(data){ // specify the ajax callback method (this receives the data back from the HTTP call if it was successful)...
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.