问题已解决。检查底部的工作代码。
首先,对不起我的英语。如果可能的话请重写我的问题。
我无法通过调用 ajax 页面使用 jquery 更改输入值。
(jquery版本http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js)
我的主页是index.php,ajax页面是ajax.php。我用
调用 ajax.php$.ajax(...
但是在使用ajax代码之后,index.php上的输入值没有改变。
这里是index.php输入代码
<input name="guncel_fiyat" type="hidden" id="guncel_fiyat" value="old value">
这里是index.php ajax调用代码:
$.ajax(
{
type: "POST",
url: "../ajax.php",
data: post_edilecek_veri,
cache: false,
success: function(donen_veri)
{
some code here;
}
}
这是 ajax.php 代码(我尝试了 3 种不同的方法,但没有任何改变)
$(".guncel_fiyat").val("new value");
或
$("#guncel_fiyat").val("new value");
或
$(".guncel_fiyat input").val("new value");
调用ajax后,尝试在index.php上获取新值,但只获取“旧值”val。
var guncel_fiyat_degeri = $("#guncel_fiyat").val();
alert(guncel_fiyat);
这是工作代码
CALL_AJAX.HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function peyfunc()
{
"use strict";
var current_price = $("#current_price").val();
alert ("current_price="+current_price);
$.ajax(
{
url: "ajax_test.php",
cache: false,
success: function(html)
{
$("#display").html(html);
}
}
);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<input name="current_price" type="hidden" id="current_price" value="5">
<input type="button" name="button" id="button" value="Button" onclick="peyfunc()">
</form>
<div id="display"></div>
</body>
</html>
AJAX_TEST.PHP
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
test
<script type="text/javascript">
//alert("aaa");
$("#current_price").val("new value");
alert ($("#current_price").val());
</script>
最佳答案
这是工作代码
CALL_AJAX.HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
function peyfunc()
{
"use strict";
var current_price = $("#current_price").val();
alert ("current_price="+current_price);
$.ajax(
{
url: "ajax_test.php",
cache: false,
success: function(html)
{
$("#display").html(html);
}
}
);
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post">
<input name="current_price" type="hidden" id="current_price" value="5">
<input type="button" name="button" id="button" value="Button" onclick="peyfunc()">
</form>
<div id="display"></div>
</body>
</html>
AJAX_TEST.PHP
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
test
<script type="text/javascript">
//alert("aaa");
$("#current_price").val("new value");
alert ($("#current_price").val());
</script>
关于javascript - jquery 不改变调用 ajax 页面的输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37027625/