Morris Chart Broken From External JSON - java

i have some problem using Morris Chart.
I want to show the details of transaction using Morris Chart using JSON from external source. Here's my code:
$(document).ready(function() {
//getting JSON data from external sources
var json_data = (function() {
var json;
$.ajax({
type:'GET',
url: 'http://localhost:8080/masterpiece/chartGetTransaction',
async: false,
global: false,
success: function(data) {
json = data;
},
error:function(){
alert("Error loading chart");
}
});
return json;
})();
//testing purposes to see whether json is shown up or not.
alert(json_data);
new Morris.Bar({
// ID of the element in which to draw the chart.
element: 'pesanan-chart-area',
data: json_data,
xkey: 'tahun',
ykeys: ['jml'],
labels: ['Jumlah'],
smooth: false
});
});
But it always broken.
The JSON itself:
[{"tahun":"2013-10-12","jml":3},{"tahun":"2013-11-16","jml":2},{"tahun":"2013-12-23","jml":4},]
when i place the JSON manually to 'data:' attribute, the chart is shown up. But when it referenced from external source (json_data var) it is broken
any ideas?
thanks.
UPDATE
update! the JSON is generated from JAVA function using third party library called json-simple (https://code.google.com/p/json-simple/downloads/list)
protected List<JSONObject> statisticPesanan(){
List<JSONObject> det = new ArrayList<JSONObject>();
try {
//create JSONObject to executed
String sql = "SELECT * FROM vstatisticpesanan";
cs = datman.logOn().prepareCall(sql);
ResultSet result = cs.executeQuery();
while (result.next()) {
JSONObject details = new JSONObject();
details.put("tahun", result.getString(1));
details.put("jml", result.getInt(2));
det.add(details);
}
} catch (SQLException se) {
Logger.getLogger(Analytics.class.getName()).log(Level.SEVERE, null, se);
java.lang.System.out.println("Error on Analytics Generate JSON Pesanan Statistics : " + se.toString());
} finally {
datman.logOff();
}
return det;
}
then called via servlet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
/* Execution of jSON Chart */
Analytics show = new Analytics();
List<JSONObject> json = show.getStatisticPesanan();
out.print('[');
for(JSONObject js : json){
out.print(js.toJSONString()+",");
}
out.print(']');
} finally {
out.close();
}
}
is there any solution? thanks.

alrite after searching and creating new function, i have realize that morris.js cannot parse the JSON object.
first change the servlet into:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
/* Execution of jSON Chart */
Analytics show = new Analytics();
List<JSONObject> json = show.getStatisticPesanan();
out.print(js.toJSONString());
} finally {
out.close();
}
}
then it will shows the right JSON object like this:
[{"1":"2013-10-12","2":3},{"1":"2013-11-16","2":2},{"1":"2013-12-23","2":4},{"1":"2014-02-11","2":10}]
then parse the JSON object into
new Morris.Bar({
// ID of the element in which to draw the chart.
element: 'pesanan-chart-area',
data: $.parseJSON(json_data),
xkey: 'tahun',
ykeys: ['jml'],
labels: ['Jumlah'],
smooth: false
});
we NEED to use function $.parseJSON to make the graph shows correctly, otherwise the graph will show undefined.
i hope this will help someone.

Related

Any method of passing the Json data in URL format using JSONObject?

I create a java URL class which contain my Json data and have some function to obtain back my json data for doing some data comparison, I found out it's might not support by JSONObject for passing the data into the JSONObject. Do I need to use JSONArray in my case because my JSON data have array structure as well?
try
{
JSONObject obj = new JSONObject ();
obj.readJsonFromUrl(theUrl);
System.out.println(obj.toString());
}
catch(MalformedURLException e)
{
System.out.print("your problem here ...1");
}
}
else
{
System.out.print("Can't Connect");
}
I am sure that this is the place give me the error message because it return me this error in my compiler
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method readJsonFromUrl(URL) is undefined for the type JSONObject
there are also some warning message for that the JSONObject readJsonFromUrl method
private static JSONObject readJsonFromUrl(URL theUrl) throws IOException, JSONException {
Anyone can provide me the explaination of how the JSON data work in java? I saw quite number of Java class for JSON which make me confuse for it such as JSONObject, JSONArray , JSONValue. I search some information online but I also not very clear about it since I am very new to JSON data processing This is my sample json data and the data I need is scan_result only
{
"data_id":"a71a3c2588c6472bb4daea41a0b58835",
"file_info":{
"display_name":"",
"file_size":242,
"file_type":"Not available",
"file_type_description":"Not available",
"md5":"aa69ba384f22d0dc0551ace2fbb9ad55",
"sha1":"09ceb54e65df3d3086b222e8643acffe451a6e8a",
"sha256":"dcb46d6ae2a187f789c12f19c44bbe4b9a43bd200a3b306d5e9c1fcf811dc430",
"upload_timestamp":"2016-11-18T09:09:08.390Z"
},
"process_info":{
"blocked_reason":"",
"file_type_skipped_scan":false,
"post_processing":{
"actions_failed":"",
"actions_ran":"",
"converted_destination":"",
"converted_to":"",
"copy_move_destination":""
},
"profile":"File scan",
"progress_percentage":100,
"result":"Allowed",
"user_agent":""
},
"scan_results":{
"data_id":"a71a3c2588c6472bb4daea41a0b58835",
"progress_percentage":100,
"scan_all_result_a":"No Threat Detected",
"scan_all_result_i":0,
"scan_details":{
"Ahnlab":{
"def_time":"2016-11-08T15:00:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":1,
"threat_found":""
},
"Avira":{
"def_time":"2016-11-08T00:00:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":133,
"threat_found":""
},
"ClamAV":{
"def_time":"2016-11-08T10:28:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":94,
"threat_found":""
},
"ESET":{
"def_time":"2016-11-08T00:00:00.000Z",
"location":"local",
"scan_result_i":0,
"scan_time":38,
"threat_found":""
}
},
"start_time":"2016-11-18T09:09:08.405Z",
"total_avs":4,
"total_time":250
},
"vulnerability_info":{
}
}
As mentioned here, there are many ways to solve this. Either you have to implement the read, parse operations yourself (#Roland Illig 's answer)
//you have to implement the readJSON method
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject json = new JSONObject(jsonText);
return json;
} finally {
is.close();
}
Or you could use a library. The most well-known and widely used libraries are jackson and gson.
The big picture is that you try to "map" your json Object to a class.
You have your json file:
{
"id":1,
"name":"eirini",
"hobbies":["music","philosophy","football"]
}
and a class that represents this file and will store the values (depending on the library that you use there might be different requirements, for example getters, setters etc..)
public class Person {
public int id;
public String name;
public List<String> hobbies = new ArrayList<String>();
public String toString() {
return name +" has the id: " + id + " the following hobbies" + hobbies.get(0) + " " + hobbies.get(2);
}
}
Finally in your main method:
public static void main(String[] args) throws IOException, ParseException {
ObjectMapper mapper = new ObjectMapper();
InputStream input = this.getClass().getResourceAsStream(FILE); //read your file. There are many ways to achieve this.
ObjectMapper mapper = new ObjectMapper(); // just need one
Person eirini = mapper.readValue(input, Person.class);
System.out.println(eirini.toString());
You cannot pass json in url, you can pass it in body. Writing Json to stream body and post it using regular java method.
Here is oracle community url of explanation of your problem.
Required Jar can be downloaded from here.
Test Code Follows:
URL url = new URL("https://graph.facebook.com/search?q=java&type=post");
try (InputStream is = url.openStream();
JsonReader rdr = Json.createReader(is)) {
JsonObject obj = rdr.readObject();
JsonArray results = obj.getJsonArray("data");
for (JsonObject result : results.getValuesAs(JsonObject.class)){
System.out.print(result.getJsonObject("from").getString("name"));
System.out.print(": ");
System.out.println(result.getString("message", ""));
System.out.println("-----------");
}
}

Error while creating a sub JSONObject from another JSONObject

I am working on an Android app and one of its functionnalities is to know when a streamer is streaming by using Twitch API.
When a streamer is streaming, if I connect to https://api.twitch.tv/kraken/streams/ I get a String which I use to build a JSON object like that :
{
"_links":{
"self":"https://api.twitch.tv/kraken/streams/srkevo1",
"channel":"https://api.twitch.tv/kraken/channels/srkevo1"
},
"stream":{
"_id":15361851552,
"game":"Super Smash Bros. for Wii U",
"viewers":42613,
"created_at":"2015-07-18T15:07:59Z",
"video_height":720,
"average_fps":59.319897084,
"_links":{
"self":"https://api.twitch.tv/kraken/streams/srkevo1"
},
"preview":{
"small":"http://static-cdn.jtvnw.net/previews-ttv/live_user_srkevo1-80x45.jpg",
"medium":"http://static-cdn.jtvnw.net/previews-ttv/live_user_srkevo1-320x180.jpg",
"large":"http://static-cdn.jtvnw.net/previews-ttv/live_user_srkevo1-640x360.jpg",
"template":"http://static-cdn.jtvnw.net/previews-ttv/live_user_srkevo1-{width}x{height}.jpg"
},
"channel":{
"_links":{
"self":"https://api.twitch.tv/kraken/channels/srkevo1",
"follows":"https://api.twitch.tv/kraken/channels/srkevo1/follows",
"commercial":"https://api.twitch.tv/kraken/channels/srkevo1/commercial",
"stream_key":"https://api.twitch.tv/kraken/channels/srkevo1/stream_key",
"chat":"https://api.twitch.tv/kraken/chat/srkevo1",
"features":"https://api.twitch.tv/kraken/channels/srkevo1/features",
"subscriptions":"https://api.twitch.tv/kraken/channels/srkevo1/subscriptions",
"editors":"https://api.twitch.tv/kraken/channels/srkevo1/editors",
"videos":"https://api.twitch.tv/kraken/channels/srkevo1/videos",
"teams":"https://api.twitch.tv/kraken/channels/srkevo1/teams"
},
"background":null,
"banner":null,
"broadcaster_language":"en",
"display_name":"srkevo1",
"game":"Super Smash Bros. for Wii U",
"logo":"http://static-cdn.jtvnw.net/jtv_user_pictures/srkevo1-profile_image-e46c53476d9b74c7-300x300.png",
"mature":null,
"status":"Evolution 2015 - Main Stage (July 17-19) all brackets http://evo2015.s3.amazonaws.com/brackets/index.html",
"partner":true,
"url":"http://www.twitch.tv/srkevo1",
"video_banner":"http://static-cdn.jtvnw.net/jtv_user_pictures/srkevo1-channel_offline_image-ee2fc39d6ebb7735-640x360.jpeg",
"_id":30917811,
"name":"srkevo1",
"created_at":"2012-05-30T16:57:11Z",
"updated_at":"2015-07-18T16:18:40Z",
"delay":0,
"followers":82134,
"profile_banner":null,
"profile_banner_background_color":null,
"views":20938144,
"language":"en"
}
}
}
This is how I get the JSON Object :
public class GetStreamStatus extends AsyncTask<Void,Void,String> {
#Override
protected String doInBackground(Void... params) {
String res = bibixChannel.getJson("streams");
return res;
}
#Override
protected void onPostExecute(String s) {
channelStatusString = s;
channelStatusObject = bibixChannel.buildJSON(s);
}
}
The buildJson() method is simply :
protected JSONObject buildJSON(String jsonRaw){
JSONObject json = null;
try{
json = new JSONObject(jsonRaw);
}catch (Exception e){
e.printStackTrace();
}
return json;
}
But after, to know if the streamer is streaming, a part of the JSON string is nulled like that :
If the streamer is streaming, you will get the fist JSON I wrote on the top of that post, else you will get something like that :
{
"_links":{
"self":"https://api.twitch.tv/kraken/streams/bibixhd",
"channel":"https://api.twitch.tv/kraken/channels/bibixhd"
},
"stream":null
}
What I want to do is getting the "stream" part in another instance variable to either recover infos about the stream or to display an offline message.
What i have got from your OP is that the channelStatusObject return you the JSONObject which contains stream key. Now what you want to check is that whether this stream is null or not. So you could do something like :-
protected JSONObject checkStream(JSONObject parentObject){
JSONObject json = (JSONObject) parentObject.get("stream");
return json; // will return null if stream is null else stream JSONObject
}
You can use this method & check its return value to see if stream is null or not.

JSON response Issue for Jira Rest Client

When I use the following method :
public String getProjectList() {
projNames = new ArrayList<>();
projNames.add("Project1");
projNames.add("Project2");
projNames.add("Project3");
return new Gson().toJson(projNames);
in the following code :
$(document).ready(function() {
$.getJSON('DBDropDown', function(resp) { // on sucess
var $select = $('#someselect');
$select.find('option').remove();
$select.prepend("<option value='Select Project'></option>").val('');
$.each(resp, function(key, value) { // Iterate over the JSON object.
$('<option>').val(key).text(value).appendTo($select); // Create HTML <option> element, set its value with currently iterated key and its text content with currently iterated item and finally append it to the <select>.
});
}).fail(function() { // on failure
alert("Request failed.");
});
});
and my JSP call is :
response.getWriter().write(MusicDatabase
.getInstance()
.getProjectList()
I am able to get the dropdown menu. But when I use this method in place of getProjectList I dont get a response when I check chrome developer tools and debug.
public String Names() throws URISyntaxException{
names = new ArrayList<>();
URI uri = new URI("https://jira.xxxxx.com");
JiraRestClientFactory jrcf = new AsynchronousJiraRestClientFactory();
JiraRestClient jrc = jrcf.createWithBasicHttpAuthentication(uri, "xxx", "xxxx");
Iterable<BasicProject> allproject = jrc.getProjectClient().getAllProjects().claim();
for(BasicProject project : allproject){
names.add(project.getName());
}
return new Gson().toJson(names);
}
I am not getting any response and console throws ClassDefNotFound Exception when I already have all the classes needed. Help me if you have gone through this type of issue.
Thanks

Keep getting an empty JSON object

Hi I'm new to JSON and I've been trying to get my List into a JSONArray, so that I can use it later with JQuery and include it on a website, but it keeps returning an empty array. I'm using Java EE and wrote a named query, I'm not too sure that the named query is the thief behind it. Here's most probably the appropiate code I hope.
The named query in Review.class:
#NamedQueries ({
#NamedQuery(name="Review.findByTitleOrName", query = "SELECT r FROM Review r WHERE r.artist.artistNr = (SELECT a.artistNr FROM Artist a WHERE a.artistName Like :A) OR r.track.trackID = (SELECT t.trackID FROM Track t WHERE t.trackTitle LIKE :A)")
})
Method in the EAO for reviews that should work:
public List<Review> getReviewsByTitleOrName(String searchParameter) {
TypedQuery<Review> tq = em.createNamedQuery("Review.findByTitleOrName", Review.class);
tq.setParameter("A", searchParameter);
List<Review> reviewList = tq.getResultList();
return reviewList;
}
Servlet code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/json; charset=utf-8");
JsonArrayBuilder arrayOfJsonReviews = Json.createArrayBuilder();
String searchParameter = request.getParameter("ajax_searchParameter");
List<Review> reviews = facade.getReviewsByTitleOrName(searchParameter);
for(Review r : reviews){
JsonObjectBuilder review = Json.createObjectBuilder();
review.add("date", r.getDate());
review.add("comment", r.getComments());
review.add("rating", r.getRating());
review.add("user", r.getUserName());
arrayOfJsonReviews.add(review);
}
response.getWriter().write(arrayOfJsonReviews.build().toString());
}
And last but not least the JQuery:
$(document).ready(function() {
$(".SearchBtn").click(function() {
console.log("Clicked button");
$.getJSON("http://localhost:8080/DynamicDolphinProject/DolphinServlet", function(data){
console.log(data);
//placeReviewDat(data);
console.log("Should have data");
});
});
//function placeReviewData(reviews){
//}
})

How to populate dropdownlist with JSON data as ajax response in jQuery

I am working on a j2ee application. In my application I have a drop-down list(or Select element). I want to populate this drop-down list with JSON data as a Ajax response.
Below is the code what I have:
Server side Code (json_source.java) which generates a JSON response. :
package demo.model;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.*;
/**
* Servlet implementation class json_source
*/
public class json_source extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
JsonArray data_json=new JsonArray();
Statement st_loginId=null;
ResultSet rs_loginId=null;
try
{
Connection con=null;
Class.forName("oracle.jdbc.OracleDriver");
/* Connection String for "OPERWH"(exadata) Database */
con=DriverManager.getConnection("jdbc:oracle:thin:*************","*****","*****");
con.setAutoCommit(true);
st_loginId=con.createStatement();
rs_loginId=st_loginId.executeQuery("select login_id \"LOGIN ID\" from user_access");
//System.out.println("entered in frame_login_code");
int login_val=0;
JsonObject json_response=new JsonObject();
while(rs_loginId.next())
{
login_val++;
JsonObject json=new JsonObject();
json.addProperty("value", "login"+login_val);
json.addProperty("text", rs_loginId.getString(1));
data_json.add(json);
}
System.out.println(data_json);
json_response.add("aaData", data_json);
response.setContentType("application/Json");
response.getWriter().write(json_response.toString());
System.out.println(json_response);
}
catch(Exception ex)
{
System.out.println("Exception occured during retrieval of Login_Id in ComboBox :"+ex);
ex.printStackTrace();
}
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
and the JSON data which successfully generated through above server side code :
{
"aaData": [{
"value": "login1",
"text": "kapils"
}, {
"value": "login2",
"text": "davidn"
}, {
"value": "login3",
"text": "alanp"
}]
}
and Below is my Client side code (source1.jsp) which generate ajax request:
(Using $.ajax() ) :
<script type="text/javascript">
$(document).ready(function()
{
$('#id_trial').click(function() {
alert("entered in trial button code");
$.ajax({
type: "GET",
url:"/demo_trial_application/json_source",
dataType: "json",
success: function (data) {
$.each(data.aaData,function(i,data)
{
alert(data.value+":"+data.text);
var div_data="<option value="+data.value+">"+data.text+"</option>";
alert(div_data);
$(div_data).appendTo('#ch_user1');
});
}
});
});
});
</script>
<body>
<div id="div_source1">
<select id="ch_user1" >
<option value="select"></option>
</select>
</div>
<input type="button" id="id_trial" name="btn_trial" value="Trial Button..">
</body>
OR Using ($.getJSON()) :
$.getJSON("/demo_trial_application/json_source", function (data) {
$.each(data.aaData, function (i, data) {
var div_data = "<option value=" + data.value + ">" + data.text + "</option>";
alert(div_data);
$(div_data).appendTo('#ch_user1');
});
});
Now when I clicked on button (#id_trial), the server side code executes successfully and as a result JSON object created. but i am not getting that "JSON response" in callback function of Success parameter using jQuery's ajax call.
and apart from jQuery's ajax call I also tried with $.getJSON function to receive JSON response..but I didn't get JSON data.
So please tell me if there is any mistake in my code, and how to get JSON data using above code and populate drop-down list.
I want to populate my dropdownlist with JSON data using ajax response.
please help me to sort out this problem...its very urgent for my application.
try to change the jquery method variable, it might be causing the problem (i.e., you are using the data variable coming from the ajax callback PLUS are then trying to assign it to the item object in the jquery method - changed to obj):
$.ajax({
type: "GET",
url:"/demo_trial_application/json_source",
dataType: "json",
success: function (data) {
$.each(data.aaData,function(i,obj)
{
alert(obj.value+":"+obj.text);
var div_data="<option value="+obj.value+">"+obj.text+"</option>";
alert(div_data);
$(div_data).appendTo('#ch_user1');
});
}
});
});
I use "for"
var List;
jQuery.ajax({
url: "/demo_trial_application/json_source",
type: "POST",
dataType: "json",
async: false,
success: function (data) {
List = data.aaData
$('#ch_user1').empty();
$('#ch_user1').append('<option value="">All</option>');
for (i in List ) {
$('#ch_user1').append('<option value="' + List[i].value + '">' + List[i].text + '</option>');
}
}
});
Working with Laravel this is my solution:
$("#YOUR_DIV").on("change", function(){
var selected = $(this).val();
makeAjaxRequest(selected);
})
function makeAjaxRequest(opts){
$.ajax({
type: "GET",
url : '{{ action('YOUR_CONTROLLER#YOUR_FUNCTION') }}',
data: { opts: opts },
success: function(data) {
NEW_JS_FUNCTION(data);
}
});
}
function NEW_JS_FUNCTION(params) {
$('#YOUR_DIV').empty();
$('#YOUR_DIV').append('<option value="">ALL</option>');
params.forEach(function(entry){
$('#YOUR_DIV').append('<option value="' + entry.KEY+ '">' + entry.TEXT + '</option>');
});
}
It works. Hope this can help.
We can populate dropdown like below . it's very easy for you all i guess.
var options = $("#options");
$.getJSON("/Country/GetAll/", function(response) {
$.each(response, function() {
options.append($("<option />").val(this.Id).text(this.Name));
});
});
<div class="col-lg-4">
<%--<input type="text" class="form-control" id="txtGender" />--%>
<select class='form-control DropDown' id="txtGender"></select>
</div>
--------------------------------------------------------------------------------
$(document).ready(function () {
$.ajax({
type: "POST",
url: "AjaxCallGrid.asmx/GetDropDown",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (result) {
$('.DropDown').empty();
$('.DropDown').append("<option value='0'>---Select---</option>");
$.each(result.d, function (key, value) {
$('.DropDown').append($("<option></option>").val(value.iD).html(value.firstName));
});
}
});
});
-------------------------------------------------------------------------
[WebMethod]
public List<Students> GetDropDown()
{
DataTable dt = new DataTable();
List<Students> result = new List<Students>();
using (SqlConnection con = new SqlConnection(#"Data Source=DOS-PC\MARJI;Initial Catalog=examples;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand("select id,firstname from Students ", con))
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
result.Add(new Students
{
iD = Convert.ToInt32(dt.Rows[i]["id"].ToString()),
firstName = dt.Rows[i]["firstname"].ToString()
}
);
}
}
return result;
}
}
The simplest way is to download this library https://github.com/JocaPC/jquery-view-engine/tree/master/src . This JQuery library directly loads JSON into dropdows and looks like a perfect match for your example. You just need to put the following code:
success: function (data) {
$('#ch_user1').view(data.aaData);
}
Take a look at this page https://jocapc.github.io/jquery-view-engine/docs/ajax-dropdown for more details.
Try as follows
<select id="xxx"></select>
success: function (response) {
for (var i = 0; i < response.length; i++) {
$("#xxx").append("<option value='" + response[i]["id"] + "'>" + response[i]["name"] + "</option>");
}
}
This is how you can do it:
$(".ddEvent").on('change', function(e){
const selectedEvent = $(this).val();
$("#ddExhibitor").empty();
$("#ddExhibitor").append("<option value='-1'>-- Choose Exhibitor --</option>");
$.ajax({
url: '/dashboard/get-exhibitors/'+selectedEvent,
type: 'GET',
success: function success(data) {
if(data.exhibitors.length > 0){
data.exhibitors.forEach(exhibitor => {
$("#ddExhibitor").append("<option value='" + exhibitor.id + "'>" + exhibitor.exhibitor_name + "</option>");
});
}
},
error: function error(err) {
alert(data.error);
}
});
});

Categories