没有真正期望得到答案,但现在有了这个2天挣扎,不知道怎么回事。浏览器挂起(等待响应?)
所以在这里我做了什么:
通过AJAX,并立即开始在后端处理它上传文件。
$.ajax({
type : "post",
cache: false,
contentType: false,
processData: false,
url : formAction,
data : formData
});
在后台我写会话存储在那里像10000 500目前的进展...
然后,我调用另一个AJAX从会话检查状态,我呼吁这个funcion每1秒钟,直到responsve回报“完成”。
看上去对我来说合法,但问题是,在后端处理完成后,第一个XHR将状态从'pending'更改为200个浏览器冻结,看起来像是阻止它,像另一个请求或somehing。 chekc屏幕波纹管。
所以它的完成,检查停止,状态更改为200,没有发生,但浏览器冻结,试图浏览器,火狐浏览器...暗示我杀的过程,但如果我等待一段时间它将刷新。
UPDATE
所以,我骗了一点点,我试图再做一次相同,但没有Ajax,看到类似的问题,后端处理完成后,浏览器应答等待(向后旋转)以后。这就是表哥挂什么。
这里是我的后端是Laravel
foreach ($chunks as $rows)
{
$current_chunk++;
if ($current_chunk < $all_chunks) {
Session::put(['import_progress'=>'Importing ' . $current_chunk * 150 . ' of ' . $all_results]);
Session::save();
} elseif ($current_chunk >= $all_chunks) {
Session::put(['import_progress'=>'done']);
}
foreach ($rows as $row)
{
// transakcija start
DB::transaction(function() use ($row) {
$code = $row[0];
$gender = $row[1];
$brand_name = filter_var($row[2],FILTER_SANITIZE_STRING);
$category = $row[3];
$subcategory = $row[4];
$condition = $row[5];
$details = $row[6];
$composition = $row[7];
$materials = $row[8];
$colors = $row[9];
$patterns = $row[10];
$country = $row[11];
$size = $row[12];
$m_a = $row[13];
$m_b = $row[14];
$m_c = $row[15];
$m_d = $row[16];
$m_e = $row[17];
$m_f = $row[18];
$m_g = $row[19];
$product = new Product();
$product->code = $code;
$product->gender = $gender;
$product->size = $country . ' | ' . $size;
$product->condition = $condition;
$product->measurement_a = $m_a;
$product->measurement_b = $m_b;
$product->measurement_c = $m_c;
$product->measurement_d = $m_d;
$product->measurement_e = $m_e;
$product->measurement_f = $m_f;
$product->measurement_g = $m_g;
$product->save();
if (empty($code)) {
$bad_prods[] = $product->id;
}
if (!empty($brand_name)) {
$brand = Brand::firstOrCreate(['brand_name'=>$brand_name]);
$product_b = new ProductBrand();
$product_b->brand_id = $brand->id;
$product_b->product_id = $product->id;
$product_b->save();
}
if (!empty($materials)) {
$materials_exp = explode(',',$materials);
foreach ($materials_exp as $material) {
$material = Material::firstOrCreate(['material_name'=>trim($material)]);
$product_m = new ProductMaterial();
$product_m->material_id = $material->id;
$product_m->product_id = $product->id;
$product_m->save();
}
}
if (!empty($patterns)) {
$patterns_exp = explode('/',$patterns);
foreach ($patterns_exp as $pattern) {
$pattern = Pattern::firstOrCreate(['pattern_name'=>trim($pattern)]);
$product_p = new ProductPattern();
$product_p->pattern_id = $pattern->id;
$product_p->product_id = $product->id;
$product_p->save();
}
}
if (!empty($colors)) {
$colors_exp = explode('/',$colors);
foreach ($colors_exp as $color) {
$color = Color::firstOrCreate(['color_name'=>trim($color)]);
$product_c = new ProductColor();
$product_c->color_id = $color->id;
$product_c->product_id = $product->id;
$product_c->save();
}
}
$product_t = new ProductTranslation();
$product_t->product_id = $product->id;
$product_t->product_title = $brand_name;
$product_t->product_description = '<p>'.$details.'</p><p>'.$composition.'</p>';
$product_t->save();
}); // end transakcija
}
}
Session::put(['import_progress'=>'done']);
Session::put(['bad_prods'=>$bad_prods]);
return redirect()->route('admin.import');
在这里,我检查状态
public function status()
{
return response()->json([
'status' => Session::get('import_progress'),
'bad_prods' => Session::get('bad_prods')
]);
}
有**的setTimeout()** **或setInterval的()**随时随地在代码的其他人呢? 在定期的时间间隔后发布你正在调用该功能的部分。 –
我也有,但没有检查状态相同的情况发生,所以它不是一个问题... – RomkaLTU
后,你都令人耳目一新的片段/检查状态 –