Hello im trying to upload a xlsx file one by one so i can show a status bar, the problem is, i did it with a for loop and while loop sending a request via ajax, but when is on the 40th element it stops and the console shows POST (site.php) net::ERR_EMPTY_RESPONSE, i tried to do it in the localhost and it works perfect, but when a i try to do it on my external server(godaddy) it shows the error. here is the code.
for(j=1;j<=tama;j++){
$.ajax({
type: "POST",
url: "ejphp.php",
dataType: "json",
data: {vals: regs, j:j},
success: function(datos){
console.log(j)
prog=datos['progreso_r'];
var id_vac=datos['id_vac']
var tipo=datos['tipo']
var tipo2=datos['tipo2']
var tot_ing=datos['tot_ing']
prog_p=Math.round(prog*100/tama);
$("#progressbar").val(prog_p);
$("#progreso").text(prog_p+'%');
$("#datos_vac").text('Id Vacuno: '+id_vac);
if(prog_p==100){
$("#aceptar").show("slow");
}
if(tipo=='error') registro(tipo2, id_vac)
subir(parseInt(prog)+1);
return false;
}
})
}
Maybe your server can't pass more than 40 requests, try to increase php memory limit and execution time. And try to browse in godaddy's admin panel.
Related
I have an Opencart website, I am currently trying to use ajax at the frontend to pass data to php controller in the backend, but I am unable to get the value from the request in backend
here is the frontend ajax code:
$.ajax({ url: 'index.php?route=checkout/cart/addAll',
type: 'post',
data: 'product_list= test' ,
dataType: 'json',
success: function(json) {});
at the backend controller, I am trying to retrieve variable "product_list" but it is not working
$products = $this->request->post['product_list'];
$logger->write("products to add to cart is"+ strval($products));
the last statement keeps printing 0 to the log file
any help with this ? what is wrong here?
I also tried
$products = json_decode($this->request->post['product_list'], true);
with same results
Ok, fixed, Ajax was not the issue, it was accessing the variable from server side, so I used $_POST
instead of $this->request->post and it is working fine
So I just did this
in file catalog/view/theme/defaulttemplate/common/home.twig I add this code at the end of the file
$(document).ready(function() {
$.ajax({url:'index.php?route=checkout/cart/addAll',
type: 'post',
data: 'product_list= test' ,
dataType: 'json',
success: function(json) {}
});
});
and in file catalog/controller/checkout/cart.php on line 479 I add this
public function addAll(){
print_r($this->request->post);
}
And I see this in my console http://joxi.ru/krDlvPdfKGejar
All I did was correct your js code. hope this helps.
I am trying to make the button post data to another PHP file through AJAX. When I run the code on XAMPP it returns the data in a dialog box perfectly fine. However, when I run it on the server, it returns the current page's HTML structure.
AJAX CODE:
$.ajax({
type: "POST",
url: "post.php",
data: {user_1: 'hello', user_2: 'hey'},
success: function(data) {
alert(data);
}
});
SERVER ALERT RESPONSE SCREENSHOT
I use ajax type for send data to php file and get response and show. In my php file i have
while($i<14){ echo $i.'<br />'; $i++;}
that return 14 replay.
So, my webpage when call data with ajax method, after some secounds, show all 14 results. But i want get live response from my ajax file.
So i want my webpage show :
1
...
and then
1
2
....
etc
This is my Ajax code that return all response together in shower div.
I want get live responses. for any responses that sent from php file
function update_table(uptype){
$("#shower").html("Loading...");
var dataString = 'type=' + uptype;
$.ajax({
type: "POST",
url: "motor.php",
data: dataString,
cache: false,
success: function(html) {
$("#shower").html(html);
}
});
return false;
}
What you are asking is not possible with your current setup.
Think of an ajax-call to a PHP-script is like visiting a website like www.example.com/yourscript.php
PHP will then server-side render a code which is sent to your web-browser. This is a one call and one answer operation. PHP will not dynamically add elements to the website. Neither will it then be able to dynamically send answers to your ajax-call. What you have to do to solve this is storing the progress of the PHP script somewhere, and do several calls to get a update on the status.
I have some ajax script that fire off about 250 synchronous PHP calls . This is my script
$(document).ready(function(){
$("#generate").html("<div class='modal'><p>Initializing...</p></div>");
$.ajax({
url:'/fetch around 250 url from database.php',
async:false,
dataType: 'json',
success: function(data){
$.each(data,function(key,val){
$("#generate").html("<div class='modal'><p>Fetching "+val.url+"</p></div>");
saveimage(val.url);
}
$("#generate").html("<div class='modal'><p>done</p></div>");
finalcreate();
},
});
});
function saveimage(){
$.ajax({
url: 'do some php work.php',
async: false,
});
}
function finalcreate(){
$.ajax({
url: 'do some php work.php',
async: false,
});
}
In the first part script fetch more than 250 urls from database and for every url script do some php calculation using another ajax call. when the loop ends script do final ajax call.
When i run this programe in firefox, it run successfully for only 40 urls, then browser shows dialog box with option of whether user want to stop this script or not, if user want to run this script then the script run again for next 40 urls , same proccess occure till the end.
How i can optimize this script, i dont want browser show option to stop this script. Please help.
Thanks
Try this:
function nextrequest() {
if (requests.length == 0) {
$("#generate").html("<div class='modal'><p>done</p></div>");
finalcreate();
return;
}
var val = requests.pop();
$("#generate").html("<div class='modal'><p>Fetching "+val.url+"</p></div>");
saveimage(val.url);
}
var requests = [];
$(document).ready(function(){
$("#generate").html("<div class='modal'><p>Initializing...</p></div>");
$.ajax({
url:'/fetch around 250 url from database.php',
dataType: 'json',
success: function(data){
requests = data;
nextrequest();
},
});
});
function saveimage(){
$.ajax({
url: 'do some php work.php',
success: function(data) {
// do something...
nextrequest();
}
});
}
function finalcreate(){
$.ajax({
url: 'do some php work.php',
});
}
You store all the URLs in a global variable, and everytime a request is done, you get the next one, until all of them are consumed, (requests.length == 0), you call the final request.
This way the user can still do something else on the page, and you can display progress everytime a request is done. Also, a good thing is that you can make 2 calls at once, or more, to make the process faster.
Ajax call needs much time to complete, as it communicates with remote server. The slowest thing there is a query to the server. You should send one batch request with all data needed to the server, that should separate the data and handle it. Everything should be completed about 250 times faster.
make some time interval for each ajax request
success: function(data){
$.each(data,function(key,val){
$("#generate").html("<div class='modal'><p>Fetching "+val.url+"</p></div>");
setTimeout(saveimage(val.url),3000);
}
I'm trying to implement a simple api request to the SEOmoz linkscape api. It works if I only use the php file but I want to do an ajax request using jquery to make it faster and more user friendly. Here is the javascript code I'm trying to use:
$(document).ready(function(){
$('#submit').click(function() {
var url=$('#url').val();
$.ajax({
type: "POST",
url: "api_sample.php",
data: url,
cache: false,
success: function(html){
$("#results").append(html);
}
});
});
});
And here is the part of the php file where it takes the value:
$objectURL = $_POST['url'];
I've been working on it all day and can't seem to find the answer... I know the php code works as it returns a valid json object and displays correctly when I do it that way. I just can't get the ajax to show anything at all!!
...data: 'url='+encodeURIComponent(url),