L
L
LyciferZla2019-10-22 18:17:46
AJAX
LyciferZla, 2019-10-22 18:17:46

How to AJAX'om get information from the server?

JS

$.ajax({
                method: "POST",
                url: "/server.php",
                data: {
                    user: user, 
                    title: title
                },
                success: function(msg){$('div.AddCoreResult').html(msg);}
            });

PHP
echo "<h1 class='SystemGood'>Успешно</h1>";
How to get " <h1 class='SystemGood'>Успешно</h1>" from the server with Ajax and display it on the page in case of a successful request?
the fact is that now for some reason it loads the entire page into a block, div.AddCoreResult
although <div class="AddCoreResult"></div>only <h1 class='SystemGood'>Успешно</h1>the entire page should be displayed in this block

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gor Mkhitaryan, 2019-10-22
@LyciferZla

In general, the correct format for communication between JS and Php is JSON. You'd better write something like A on the js side justecho json_encode(['msg' => 'Успешно']);

$.ajax({
                method: "POST",
                url: "/server.php",
                data: {
                    user: user, 
                    title: title
                },
                success: function(msg){$('div.AddCoreResult').html("<h1 class='SystemGood'>"+msg.msg+"</h1>");}
            });

Also don't forget to include header Content-type: application/json in php file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question