[英]form submit without refreshing page using ajax
i have old code, that has jquery v1.9. 我有旧代码,有jquery v1.9。 now for some new edit, i need to submit form without refreshing page using ajax.
现在进行一些新的编辑,我需要提交表单而不使用Ajax刷新页面。 but it dose not work.
但它不起作用。 and when i change version of jquery, old script dose not work.
当我更改jQuery的版本时,旧脚本无法正常工作。 my code is here: days.php:
我的代码在这里:days.php:
<script>
$(document).ready(function(){
$('#formSubmit').click(function(){
$.post("day2.php",
{name: $('#name').val()},
function(data){
$('#response').html(data);}
);});});
</script>
<div>
<input type="text" id="name">
<button id="formSubmit">send</button>
<textarea id="response"></textarea>
</div>
and day2.php: 和day2.php:
$name = $_POST['name'];
echo "response: " +$name;
i dont know where is problem! 我不知道哪里出了问题!
try: 尝试:
echo "response: " . $name;
instead of: 代替:
echo "response: " +$name;
Actual problem is in second file where in 实际问题出在第二个文件中
echo "response: " +$name;
you have used + as string concatenation operator instead of '.' 您已使用+作为字符串连接运算符,而不是'。'。
so actual code is like this 所以实际的代码是这样的
echo "response: " .$name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.