The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to make ajax update by oldest post
The_webmaster
post Feb 9 2021, 11:31 AM
Post #1


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



Please who can help me, I have an ajax that display submited data/post but i want it to show latest post ontop and oldest post at the bottom.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 9 2021, 11:58 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



Please post the script you're currently using.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Feb 9 2021, 02:38 PM
Post #3


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



This is the code
CODE
<form method="post"> Enter your text: <input type="text" id="post"> <input type="submit" value="post" id="save"> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> <script> $(document).ready(function(){ $('#save').click(function(){ var post = $('#post').val(); $.ajax({ type: 'post', data: {name: post}, success: function(response){ $('#response').text('name:' + response); } }); }); }); </script> <div id="response"><div>


This post has been edited by The_webmaster: Feb 9 2021, 02:41 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 9 2021, 04:33 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



I'm not good at jQuery or Ajax, but there's no URL to any server-side script (say PHP) that could handle the Ajax request, so I don't think it could work the way it looks now.

If you want to display all previous form submissions on the web page, you have to request them from the server (with say PHP, which in turn could make an SQL request to a database, if you use that).

The order of the previous form submissions could be handled by the PHP script, or maybe the SQL request, or maybe by jQuery. What is the best method may depend on how it's saved on the server.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
The_webmaster
post Feb 9 2021, 11:42 PM
Post #5


Member
***

Group: Members
Posts: 40
Joined: 5-February 21
Member No.: 27,773



Url is not added to ajax when the same page is the processing page.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Feb 10 2021, 03:12 AM
Post #6


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(The_webmaster @ Feb 9 2021, 10:42 PM) *

Url is not added to ajax when the same page is the processing page.

This is true, if the form is submitted. ajax doesn't submit the form, so the same page can't process it. ajax does allow you to run a script on the server, get the results, then you can put the info into your web page. For this reason ajax does require a url. The url should be to the script that will process the data. The form is never submitted so you have to include a name/value pair for every element you want to pass to the script. I don't do jQuery so I've stayed out.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 06:41 PM