Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
systems:yii2:using_ajax [2018/05/31 10:53] smayr [Using JQuery $.get() or $.post()] |
systems:yii2:using_ajax [2018/05/31 11:16] (current) smayr [Using JQuery $.get() or $.post()] |
||
---|---|---|---|
Line 136: | Line 136: | ||
== Using JQuery $.get() or $.post() == | == Using JQuery $.get() or $.post() == | ||
- | You can also get data without | + | You can also get data using a simplified |
+ | |||
+ | Using GET method: | ||
<code php> | <code php> | ||
- | <?= $form-> | + | <?= $form-> |
- | | + | ' |
- | | + | ' |
- | // | + | // |
- | | + | |
- | var url = "' | + | |
- | | + | |
$( "# | $( "# | ||
}); | }); | ||
- | ']); | + | ', |
- | ?> | + | ]) ?> |
</ | </ | ||
+ | |||
+ | Using POST method: | ||
+ | <code php> | ||
+ | <?= $form-> | ||
+ | ' | ||
+ | ' | ||
+ | var anId = $(this).val(); | ||
+ | var aUrl = "' | ||
+ | | ||
+ | url: aUrl, | ||
+ | data: {id: anId}, | ||
+ | success: function( data ) { | ||
+ | $( "# | ||
+ | }, | ||
+ | error: function (xhr, status, errorThrown) { | ||
+ | console.log(" | ||
+ | console.log(" | ||
+ | console.dir( xhr ); | ||
+ | }, | ||
+ | dataType: " | ||
+ | }); | ||
+ | ', | ||
+ | ]) ?> | ||
+ | </ | ||
+ | |||
=== Examples === | === Examples === | ||
Line 187: | Line 213: | ||
$( " | $( " | ||
.append( "Name: " + data.name ) // John | .append( "Name: " + data.name ) // John | ||
- | .append( "Time: " + data.time ); // 2pm | + | .append( "Time: " + data.time ); // 2pm |
}, " | }, " | ||
</ | </ |