-1

I'm trying to create a js that send data to a php.

My first problem is that I get get back a html code if I insert this to the php.

This is only for understand the idea. So the js should send the "param" to the php and the php should return the result6 variable in this case, but I get a html code...

$('#f_field').change (function() 
  {
  var param = 28;
  $.post('check_mutet.php', param, function(result6) {

          alert(result6);

    });

   }); 

while check_mutet.php contains this

<?php


$result6=666;

echo $result6;

Thank you for your help, as you can see I'm rather noob :)

Grax
  • 3
  • 1
  • I don't understand what the problem is. The variable `result6` contains the value `666`. What exactly should happen? – Scriptim Mar 17 '19 at 14:40
  • Sorry, the cause of the problem was the initial part of the code that checked the permissions, but I didn't included it in the short code that was pasted here. – Grax Mar 18 '19 at 15:03
  • So the result was a permission denied page and I got the code of that page instead of 666. – Grax Mar 18 '19 at 15:10

1 Answers1

-1

param is a plain string (it starts out as a number, but will be converted to a string by the time it gets through to HTTP).

This will be available as STDIN in PHP, which you can read as described in answers to this question.

However, you should encode the data into a structured format that is easier to use.

The traditional format for this is application/x-www-form-urlencoded, which is the default format sent by HTML forms.

If you pass an object to jQuery post, it will encode the data in that format for you:

var param = 28;
var data = { example: param };
$.post('check_mutet.php', data, function(result6) {

Then you can read it through the POST superglobal in PHP:

<?php
    $result = $_POST['example'];
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335