We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Not Filling from DataSource

Thread ID:

Created:

Updated:

Platform:

Replies:

144373 May 2,2019 09:07 PM UTC May 6,2019 05:38 AM UTC JavaScript - EJ 2 3
loading
Tags: DropDownList
Jahanzeb Khan
Asked On May 2, 2019 09:07 PM UTC

<div class="container">
<input type=text id="test" name="test"/>
<script language="JavaScript">
$( document ).ready(function() {

$.ajax({url: "getDDValues.php?action=getStatuses", success: function(result){
alert("Here");
var dat = JSON.stringify(result);
alert(dat);
//The alert shows the data below
//dat = [{"value":"NEW","text":"NEW"},{"value":"Accepted","text":"Accepted"}];
$("#test").ejDropDownList({dataSource:dat,fields: { text: "text", value: "value" }});
}});
});
</script>
</div>
When I get the json data from the url, it is identical to the dat variable commented out.  I get an error:
Uncaught TypeError: Cannot read property 'slice' of undefined
    at Object._getFilteredList (ej.web.all.min.js:10)
    at Object._showFullList (ej.web.all.min.js:10)
    at Object._render (ej.web.all.min.js:10)
    at Object._init (ej.web.all.min.js:10)
    at new <anonymous> (ej.web.all.min.js:10)
    at w.fn.init.n.fn.(anonymous function) [as ejDropDownList] (http://{mysite}/EJ/Scripts/web/ej.web.all.min.js:10:24083)
    at Object.success (test1.php:69)
    at u (jquery-3.3.1.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js:2)
    at k (jquery-3.3.1.min.js:2)
_getFilteredList @ ej.web.all.min.js:10
_showFullList @ ej.web.all.min.js:10
_render @ ej.web.all.min.js:10
_init @ ej.web.all.min.js:10
(anonymous) @ ej.web.all.min.js:10
n.fn.(anonymous function) @ ej.web.all.min.js:10
success @ test1.php:69
u @ jquery-3.3.1.min.js:2
fireWith @ jquery-3.3.1.min.js:2
k @ jquery-3.3.1.min.js:2
(anonymous) @ jquery-3.3.1.min.js:2
load (async)
send @ jquery-3.3.1.min.js:2
ajax @ jquery-3.3.1.min.js:2
(anonymous) @ test1.php:64
l @ jquery-3.3.1.min.js:2
c @ jquery-3.3.1.min.js:2
setTimeout (async)
(anonymous) @ jquery-3.3.1.min.js:2
u @ jquery-3.3.1.min.js:2
fireWith @ jquery-3.3.1.min.js:2
fire @ jquery-3.3.1.min.js:2
u @ jquery-3.3.1.min.js:2
fireWith @ jquery-3.3.1.min.js:2
ready @ jquery-3.3.1.min.js:2
_ @ jquery-3.3.1.min.js:2
When I uncomment the dat variable it works fine.
Can you please help me fill the list from the URL
Thanks,
JK

Prince Oliver [Syncfusion]
Replied On May 3, 2019 09:03 AM UTC

Hello Jahanzeb,  
 
Greetings from Syncfusion support. 
 
We have prepared a sample with your code and able to replicate the issue. It seems the dataSource format is not returned correctly when using JSON.stringify. We have fetched data from OData services and mapped the result of JSON objects to “dat” variable which will be assigned as dataSource for DropDownList. Please refer to the below screenshot for the format of data returned in our end.  
 
 
 
As we are not aware of the data returned from the URL mentioned in your code, please ensure whether data is returned in this format. Also, you need not stringify this data as done in your code and directly set the array of JSON objects as dataSource. Please find the code used in our sample below.  
 
<script language="JavaScript"> 
    $( document ).ready(function() { 
        $.ajax({url: 'https://services.odata.org/V4/Northwind/Northwind.svc/Customers', success: function(result){ 
            var dat = result.value; 
            console.log(dat); 
            //The alert shows the data below 
            //dat = [{"value":"NEW","text":"NEW"},{"value":"Accepted","text":"Accepted"}]; 
            $("#test").ejDropDownList({dataSource:dat,fields: { text: "CustomerID", value: "CompanyName" }}); 
        }}); 
    }); 
</script> 
 
Kindly refer to the following link for the sample: 
 
Let us know if you need any further assistance on this. 
 
Regards, 
Prince 


Jahanzeb Khan
Replied On May 3, 2019 09:31 PM UTC

Prince,

Dumb error on my part!

Thanks for all your help, it fixed the issue.

Regards,

JK

Prince Oliver [Syncfusion]
Replied On May 6, 2019 05:38 AM UTC

Hello Jahanzeb,   

Most welcome. We are glad to help you. 

Regards, 
Prince 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon