Jump to content

POST variables to page via ajax


Recommended Posts

hi i want to post variables to a page via ajax to get result from my database depenting my post value
so my ajax is:

var clickval = clickelement.value;
var dataval = "city=" + clickval;

type: 'POST',
url: "*MY PAGE SMART URL*", // e.g. http://my_domain/my_page....
data: dataval,
dataType: 'text', //or json, i try both
complete: function(data, status){




and in php page: 

$getcity = $input->post->city;
echo "value = ".$getcity;

just to show my post value...
and my alert is "value = ".
$getcity is empty and $input has no value inside and it seems like post is never be done, but i have no error in my console...
can anyone help me?

Edited by LostKobrakai
Added codeblocks
Link to comment
Share on other sites

Have a read here: https://processwire.com/talk/topic/225-how-to-work-with-ajax-driven-content-in-processwire/

It would be good to use $config->ajax; (or wire('config')->ajax if within a function

Welcome to ProcessWire and the forums


Your code is probably just an example but you need to sanitize your inputs before saving them and entitiy encode them if you are going to be echoing them back to the user immediately

Edit 2:

What Soma said below :-)

Edited by kongondo
Link to comment
Share on other sites

  • 1 year later...
  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...