Does AJAX not call PHP?

Can someone point out what I'm doing wrong, I'm trying to make a php call when changing the selected value.

The code does not reflect information from the php file.

REDUCTION CODE

// Skill sort on change $('#order_by').on('change', function() { $.ajax({ type: "POST", url: "sort_skill_be.php", data: {skill:this.value} }).done(function(result){ console.log(result) }) }); 

PHP code

 <?php session_start(); $skill_sort = $_POST['skill']; echo $skill_sort; echo 'I got in here'; ?> 

Thanks for the help and time!

EDIT: it is working right now, thanks for the help!

+4
source share
4 answers

Try the following:

 $('#order_by').on('change', function() { var sk = $(this).val(); $.ajax({ type: "POST", url: "sort_skill_be.php", data: 'skill=' + sk, success: function(result) { alert(result); } }); }); 
+4
source

try it

 $('#order_by').on('change', function() { $.ajax({ type: "POST", url: "sort_skill_be.php", data: {skill:$(this).val()}, success: function(result){ alert("done"); }, error: function(){ alert("error"); } }); }); 
+1
source

You should use then instead of done http://promises-aplus.imtqy.com/promises-spec/

 $('#order_by').on('change', function () { $.post("sort_skill_be.php", { skill: $(this).val() }).then(function (result) { console.log(result); }).fail(function () { console.err('failed to fetch data'); }); }); 
+1
source

You can check how this happens ...

 // Skill sort on change $('#order_by').on('change', function() { $.ajax({ type: "POST", url: "sort_skill_be.php", data: {skill:this.value} }).done(function(result){ console.log('my results' + results); }) }); 
0
source

Source: https://habr.com/ru/post/1487376/


All Articles