Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2024-08-21 20:32:06

lindabb
Member
Registered: 2023-02-17
Posts: 132

ajax not working

Hello,
I have simple ajax, works in normal php, but doesn’t in Textpattern, any idea?
here is the code: in single page.

<!doctype html>
<html>

<head>

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

</head>


<body>



		<form id="loginform" method="get">
			<div>
				Username:
				<input type="text" value="user1" name="username" id="username" />
	  		Password:
				<input type="password" value="pass1" name="password" id="password" />    

				<input type="submit" name="loginBtn" id="loginBtn" value="Login" />
			</div>
		</form>


<txp:php>
if (isset($_POST['username']) && isset($_POST['password']) ) {

	echo $_POST['username'] .'<br>';  
	echo $_POST['password'] ; 


} 

</txp:php>


<script type="text/javascript">
$(document).ready(function() {
    $('#loginform').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'GET',
            data: $(this).serialize(),
            success: function(response)
            {
             //   var jsonData = JSON.parse(response);


           }
       });
     });
});
</script>

</body>
</html>

Offline

#2 2024-08-22 03:15:39

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,635
GitHub Twitter

Re: ajax not working

The use of PHP code within Textpattern: https://docs.textpattern.com/tags/php.


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#3 2024-08-22 12:35:17

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: ajax not working

Thank you,
if you are talking about add my php code as:

<notextile> <txp:php>

if (isset($_POST[‘username’]) && isset($_POST[‘password’]) ) {

echo $_POST[‘username’] .’<br>’; echo $_POST[‘password’] ;
}

</txp:php> </notextile>

I tried that too, still not working, I don’t see any error.
is there any other way to add ajax call into textpattern ? is it possible ?

Thank you

Offline

#4 2024-08-22 13:00:12

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,734
Website

Re: ajax not working

For the front-side, there should be no limitations. Take another look at your code: it looks like you have a mix of POST and GET methods in there, which is probably why you’re not seeing anything returned via your PHP. Otherwise, you may find POST is better for sensitive data inputs like passwords.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2024-08-22 13:57:40

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: ajax not working

Thank you,
I think the issue with   data: $(this).serialize(), 
can’t see the form, I have passed values manfully and worked

var user = $(‘#username’).val();
var pass= $(‘#password’).val();

You are correct; I was playing around to see if that makes any difference. I have all get, I will make them all post

Last edited by lindabb (2024-08-22 14:02:35)

Offline

Board footer

Powered by FluxBB