TheCoffee TheCoffee - 5 months ago 20
Ajax Question

Cant Send Value To PHP String With AJAX

What is the actual deal in the Data part ?

<form id="form" name="form">
<input type="text" name="textname" id="textname">
<input type="button" name="submit" id="submit" onclick="post();">

function post()
var textname = $('#textname').val();

url: 'post.php',
data: {testurl:textname},
type: "POST",
success: function (data)

And the post.php

echo "test";

$testurl = $_POST['textname'];

echo var_dump($testurl);

Echo Test is working but Output for the var_dumb is NULL string(0) - Empty String


Try to understand one simple thing, in ajax call the data parameter contains the

key : value

pair in it.

Means if your data part is some thing like:

data: {
   var1 : val1,
   var2 : val2,

than in your php function you can get these values using its keys i.e. var1, var2.