Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX global vars
    primarykey
    data
    text
    <p>I'm trying to do this, which returns 'undefined':</p> <pre><code>$.ajax({ url : 'curriculum/read_types', type : 'GET', dataType : 'JSON', success : function(data) { return data; } }) </code></pre> <p>But if I do this:</p> <pre><code>$.ajax({ url : 'curriculum/read_types', type : 'GET', dataType : 'JSON', success : function(data) { console.log(data); } }) </code></pre> <p>it writes an entire JSON object on the console, so I know there exists data.</p> <p>How I can return this data?</p> <hr> <p>What I want to do is the next:</p> <pre><code>var curriculum = { add : function() { html = []; html.push('&lt;select name="type" required&gt;'); html.push('&lt;option value="0"&gt;Grupo general...&lt;/option&gt;'); var types = curriculum.read_types(); $.each(types, function(k,v) { html.push('&lt;option value="'+v+'"&gt;'+v+'&lt;/option&gt;') }) html.push('&lt;/select&gt;'); content.show('Añadir imagen a curriculum',html.join('')); }, read_types : function() { $.getJSON('curriculum/read_types', function(data) { return data; }) } } curriculun.add() </code></pre> <hr> <p>Finally it managed but with a asyn:false request:</p> <pre><code>var curriculum = { add : function() { html = []; html.push('&lt;select name="type" required&gt;'); html.push('&lt;option value="0"&gt;Grupo general...&lt;/option&gt;'); var types = curriculum.read_types(); $.each(types, function(k,v) { html.push('&lt;option value="'+v+'"&gt;'+v+'&lt;/option&gt;') }) html.push('&lt;/select&gt;') content.show('Añadir imagen a curriculum',html.join('')); }, read_types : function() { var a; $.ajax({ url : 'curriculum/read_types', type : 'GET', async : false, contentType : 'JSON', success : function(data) { a = data; } }) return a; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload