这是我的javascript部分:
<script>
$(document).ready(function(){
$(".annotator-save").click(function () {
var value=$('#jid').text();
$.ajax({ url: '/response/insert',
data: {val: value}, i want this to directly go to the function
insert.
i.e the text has to be displayed.
type: 'post',
success: function(output) {
alert(output);
}
});
</script>
我的ajax代码出了什么问题?
and my php function is-
<?php
function insert()
{
echo $_POST_['val'];
return $_POST_['val'];
}
?>
it is entering the php file but not the insert function
答案 0 :(得分:0)
您正在声明该功能但未调用它。即。
<?php
function insert()
{
echo $_POST_['val'];
return $_POST_['val'];
}
insert();
?>
答案 1 :(得分:0)
如果您在该特定文件中可能有多个函数,则可能需要执行以下操作。
$.ajax({ url: '/response/insert',
type: 'POST',
data: {val: value, action : 'INSERT' },
success: function(){}
});
// in your php
if($_POST['action']=='INSERT'){
insert($_POST['val']);
}
elseif........//all your actions. Try to state all your actions, return error on else
function insert($val){}
function delete(){}
答案 2 :(得分:0)
$。ajax({url:'/ response / insert',
请尝试使用完整的网址,如:http://localhost/masujan.com/index.php/admin_home/view_portfolio 我觉得它有用。 哦!无需返回此&gt;返回$ POST ['val'];