JSON值未设置为JQUERY中的文本框 [英] JSON Value not set to textbox in JQUERY
本文介绍了JSON值未设置为JQUERY中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在php中有一个代码,它返回一行JSON。
public function getEmploymentDetailsForEdit($ id){
$ query = < span class =code-string> select * from js_employment_details where email_id ='。$ _ SESSION [' username']。 ' 跨度>;
$ res = mysql_query($ query);
$ row = mysql_fetch_array($ res);
echo json_encode($ row);
}
从jquery函数下面调用函数
function editEmploymentDetails(id){
$ .ajax({
type: POST,
url:' getEmploymentDetailsForEdit.php',
data:{id:id},
success: function (response){
console .log(response);
$( #expDesignation)。val(响应[ 0 ] [' names']);
$( #txtOrganization )。val(响应[ organization]);
< span class =code-comment> // $()。val(response [designation]);
$ ( #startDate)。val(响应[ starts_date]);
$( #endDate)。val(response [ ends_date]);
$( #txtJobProfile)。val(response [ job_profile]);
$( #btnEmployment)。val( 更新);
}
});
}
当函数成功时,响应正常,但值未设置为文本框。
解决方案
id){
query = select * from js_employment_details where email_id ='。
_SESSION [' < span class =code-string> username']。 ';
i have a code in php which returns me JSON of a single row.
public function getEmploymentDetailsForEdit($id){
$query="select * from js_employment_details where email_id='".$_SESSION['username']."'";
$res=mysql_query($query);
$row=mysql_fetch_array($res);
echo json_encode($row);
}
the function is called from below jquery function
function editEmploymentDetails(id){
$.ajax({
type:"POST",
url:'getEmploymentDetailsForEdit.php',
data:{id:id},
success:function(response){
console.log(response);
$("#expDesignation").val(response[0]['designation']);
$("#txtOrganization").val(response["organization"]);
//$("").val(response["designation"]);
$("#startDate").val(response["starts_date"]);
$("#endDate").val(response["ends_date"]);
$("#txtJobProfile").val(response["job_profile"]);
$("#btnEmployment").val("Update");
}
});
}
when the function enters success the response is coming proper but it the value is not set to the textbox.
解决方案
id){
query="select * from js_employment_details where email_id='".
_SESSION['username']."'";
这篇关于JSON值未设置为JQUERY中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文