问题描述
我有一个具有两种形式的php页面.在第一种形式中,有一个按钮,按钮的onclick()调用用于验证第一种形式的函数.如果所有的验证都完成了 else
部分函数的内容如下:
I have a php page with two forms.In first form there have a button ,onclick() of the button call a function for validating the first form.if validations are all did theelse
part of the function is below:
else
{
var cnt=$("#frmdocontact").serialize();
$.ajax({
type: "POST",
url: "doitcontact.php",
data: cnt,
success: function(msg){
var spt=msg.split('#$@$');
$('#hid_uid').val(spt[0]);
$('#hid_add_vehicle').val(spt[0]);
$('#hid_saleid').val(spt[1]);
//alert(msg);
//console.log(contactSent);
var pkg = $('input:radio[name=pkg]:checked').val();
var $tabs = $('#tabs').tabs();
var selected = $tabs.tabs('option', 'selected');
$tabs.tabs('select', selected+1);
//window.location="thankyou.php"
}
});
}
其他部分起作用后, hd_saleid
的值为 OFKXM
. hd_saleid
为第二种形式.
after the else part worked ,the hd_saleid
have value as OFKXM
.The hd_saleid
is in second form.
第二种形式有文件上传部分,这是通过使用ajax上传完成的.但是在该ajax上传功能中, hd_saleid
的值没有得到.这是代码:
In second form there have file upload section ,that is done by using ajax upload.But in that ajax upload function the hd_saleid
value is not getting.This is the code:
$(function(){
var cntUp = 0;
var btnUpload=$('#upload');
var status=$('#status');
var saleid = $("#hd_saleid").val();
new AjaxUpload(btnUpload, {
action: 'upload-file.php',
data: {saleid: $("#hd_saleid").val()},
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
alert('Only JPG, PNG or GIF files are allowed');
return false;
}
status.text('Uploading...');
},
onComplete: function(file, response){
//On completion clear the status
status.text('image uploaded');
cntUp++;
//console.log(cntUp);
//Add uploaded file to list
if (response.toLowerCase().indexOf("success") >= 0 ) {
//alert('success');
//$('<li></li>').appendTo('#files').html('<img src="uploads/'+file+'" alt="" /><br />'+file).addClass('success');
if(saleid){
$('<li></li>').appendTo('#files').html('<img src="uploads/'+saleid+'/'+file+'" alt="" /><br />'+file).addClass('success');
}else{
$('<li></li>').appendTo('#files').html('<img src="uploads/'+file+'" alt="" /><br />'+file).addClass('success');
}
} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
//alert('error');
}
}
});
});
那么我如何在Ajax上传中获取 hd_saleid
的值隐藏字段?
So how can i get the value hidden field of hd_saleid
in ajax upload?
推荐答案
是的,您的问题在这里:
Yes, your problem is here:
var saleid = $("#hd_saleid").val();
当DOM准备就绪时,
saleid
从 $(#hd_saleid").val()
中获取它的值,因此它在开始时就获取了他的值.这就是为什么您必须直接在AJAX调用中添加 $(#hd_saleid").val()
的原因.
saleid
takes it's value from $("#hd_saleid").val()
when the DOM is ready, so it takes his value at start and that's it. That why you had to add $("#hd_saleid").val()
directly in AJAX Call.
您可以使用:
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
alert('Only JPG, PNG or GIF files are allowed');
return false;
}
this.setData({
'saleid': $("#hd_saleid").val()
});
status.text('Uploading...');
},
这篇关于ajax调用后未获得文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!