[英]Transferring data via ajax to php
I resolve the problem with the format but I have a new problem in the transfer of the data by ajax to my php. 我解决了格式问题,但是在ajax将数据传输到PHP时遇到了新问题。
Ajax send data like: Ajax发送数据的方式如下:
$.ajax({
url: 'http://localhost/test-fullcalendar/php/add_evento.php',
data: 'title='+ title+'&start='+ start +'&end='+ end ,
type: "POST",
success: function(json) {
alert('OK');
}
});
And add_evento.php receive like: 并且add_evento.php收到像:
$title=$_POST['title'];
$start=$_POST['start'];
$end=$_POST['end'];
It says me 'undefined index' in all of the variables so I included 'isset' in anyone. 它在所有变量中都说“未定义索引”,因此我在任何人中都包含了“ isset”。 After that I did an echo of the variables and none receives correctly the data, all of them didn't show anything.
之后,我对变量进行了回显,但没有一个正确地接收到数据,所有这些变量均未显示任何内容。 I try to changing the data line to:
我尝试将数据线更改为:
data: {title: title, start: start, end: end},
and the method POST to GET and still doesn't working. 并且方法POST到GET仍然不起作用。
How I can check if I sending correctly the data? 如何检查我是否正确发送了数据? I'm writing alert(data.title);
我正在写alert(data.title); inside ajax function but don't show anything.
在ajax函数内部,但不显示任何内容。
Your data is incorrect. 您的数据不正确。 Try this:
尝试这个:
$.ajax({
url: 'http://localhost/test-fullcalendar/php/add_evento.php',
data: {"title": title, "start": start, "end": end},
type: "POST",
success: function(json) {
alert('OK');
}
});
If type: "POST"
you can access data with $_POST
and if type: "GET"
you can access with $_GET
如果
type: "POST"
,则可以使用$_POST
访问数据;如果type: "GET"
,则可以使用$_GET
访问数据
data: 'title='+ title+'&start='+ start +'&end='+ end
This should be changed to: 这应该更改为:
data: {title:title, start:start, end:end}
You can also do the call like this: 您也可以像这样进行通话:
$.post('http://localhost/test-fullcalendar/php/add_evento.php',{title:title, start:start, end:end}, function(json) {
alert('OK');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.