AJAX Crashes Chrome - ajax

Umm.. my problem is that i want to use ajax for my chatbox but whenever i try to put ajax for no-reload refresh Chrome/Firefox Crashes down.. HERE's my code:
/chatlog.php/
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
//<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$.ajaxSetup({ datatype: "html" });
$('#loaddiv').load('chatlog.php');
}, 10000);
</script>
/submit.php/
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".submit").click(function(){
var message = $("#message").val();
var dataString = 'message'+message;
$.ajax({
type: "POST",
url: "submit.php",
data: dataString,
async: false,
});
/*$message=$_POST['message'];
$name = $_SESSION['username'];
$room = $_SESSION['room'];
$user = $_SESSION['user'];*/
});
});
</script>

$.ajax({
type: "POST",
url: "submit.php",
data: { message : message },
async: false
});
Also put your ajaxSetup outside of the setInterval function.
$.ajaxSetup({ datatype: "html" });

Pass your data properly, like:
var dataString = 'message'+message;
//Should Be
var dataString = 'message='+message;
//OR
var dataString = {'message' : message };

Related

laravel-excel: How to use progress bar when exporting

Now my download is ok. I think use a progress bar is better. I see this: https://docs.laravel-excel.com/3.1/imports/progress-bar.html
But it's for imports. And I want to use in blade, ajax. Can someone give me some suggestion?
<script type="text/javascript"><!--
$('#button-export-save').on('click', function () {
var dataString = $('#excel-form').serialize();
$.ajax
({
type: "POST",
url: "{{ route('lang.admin.member.members.export') }}",
data: dataString,
cache: false,
xhrFields:{
responseType: 'blob'
},
success: function(data)
{
var link = document.createElement('a');
link.href = window.URL.createObjectURL(data);
link.click();
},
fail: function(data) {
alert('Not downloaded');
}
});
});
//--></script>

Can't post ajax value

Still stack in these code. On any browser desktop working fine, but when try use chrome on my android, can't post value from ajax datastring.
jQuery(document).ready(function()
{
jQuery(".button").click(function()
{
var product = jQuery(".products").val().split('|')[0];
var nomortujuan = jQuery(".nomortujuan").val();
var pn = parseFloat(document.getElementById("val[pin]").value);
var dataString = 'method=sendMessage&message='+product+'.'+ nomortujuan+'.'+pn;
var web = 'ajax.php';
jQuery.ajax ({
type: "POST",
url: web,
data: dataString,
cache: true,
beforeSend: function(html) {
document.getElementById("hasil").innerHTML = '';
jQuery(".flash").show();
jQuery(".flash").html('<div style="float:left;"></div>');
},
success: function(html){
jQuery("#js_process_request input, #js_process_request select").attr('disabled',false);
jQuery(".flash").hide();
jQuery("#hasil").hide();
jQuery ("#hasil").append(html);
return false;
}
});
});
});
Maybe this problem
jQuery ("#hasil").append(html);
remove spacing to fix it
jQuery("#hasil").append(html);

not pass my json arrays to php, I dont know why

My code is not working in browser, and not send datas to process.php. I don't know where is the problem.
My original js data structure - data-today.php (which daily updated and I open after the head)
var football = new Array(); football[0] = new Array('Argentina','Primera Division','Boca Juniors'); football[1] = new Array('Argentina','Primera Division','Lanús'); football[2] = new Array('England','Premier League','Arsenal'); football[3] = new Array('England','Premier League','Liverpool');
And here is my code, and I would like to pass all datas to a simple html dom parser. I don't know where is the problem.
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="json2.js">
</script>
<script src="data-today.php" type="text/javascript" language="javascript"></script>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
$(document).ready(function () {
var json = JSON.stringify(football);
for (var i = 0; i < json.length; i++) {
alert(json);
$.ajax ({
type:"POST",
url:"process.php",
contentType: "application/json",
dataType: "json",
async: true,
data: {
country: $("json[i][0]"),
competition: $("json[i][1]"),
team: $("json[i][2]")},
success: function(){ alert("data")},
error: function(){ alert("error")}
});
}
});
</script>
<table>
</table>
</body>
</html>
You have the data already nicely in javascript array and if you really want to post the data in the for loop you can use something like below.
$(document).ready(function ()
{
// scrap that line, you have the values in array (of arrays)
//var json = JSON.stringify(football);
for (var i = 0; i < football.length; i++)
{
//alert(json);
$.ajax ({
type:"POST",
url:"process.php",
contentType: "application/json",
dataType: "json",
async: true,
data: {
country: football[i][0],
competition: football[i][1],
team: football[i][2],
success: function(){ alert("data")},
error: function(){ alert("error")}
});
}
});
You probably should also rename your data-today.php to data-today.js as it seems to be a javascript file instead of php one...
(1) var football is an array, so when you do var json = JSON.stringify(football); it turns it into a string, so when you do for (var i = 0; i < json.length; i++) { it is looping over the string chars, and not an array.
(2) if json is an array, then there is no need to make it an object - $("json[i][0]"). just access it directly - json[i][0].
So now your code should look like
<script language="javascript" type="text/javascript">
var football = new Array();
football[0] = new Array('Argentina','Primera Division','Boca Juniors');
football[1] = new Array('Argentina','Primera Division','Lanús');
football[2] = new Array('England','Premier League','Arsenal');
football[3] = new Array('England','Premier League','Liverpool');
$(document).ready(function () {
var json = football;
for (var i = 0; i < json.length; i++) {
$.ajax({
type:"POST",
url:"process.php",
contentType: "application/json",
dataType: "json",
async: true,
data: {
country: json[i][0],
competition: json[i][1],
team: json[i][2]},
success: function(){ alert("data")},
error: function(){ alert("error")}
});
}
});
</script>
jsFiddle example - http://jsfiddle.net/pdrw4r73/1/ (I commented out the alert("error") in error: function(){ alert("error")}, but you can expand the POST in the Firebug Lite to see the $.ajax() posts.)
Thanks for the answers for everybody. If I try to update my code I got this error at firefox console: SyntaxError: expected expression, got '}' , somwhere before the </script> tag. I tried both version, but the result is the same if I try to open my process.php.
my process.php:
<?php
include ("auto3.php");
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>

Passing Local Storage Variable to AJAX URL?

How can I pass a local storage variable into the AJAX url:
My problem is the variable "url" won't pass into the url section where I put + url +
Any help would be greatly appreciated. Thanks John
<script id="source" language="javascript" type="text/javascript">
$(function ()
{
$.ajax({
var url = localStorage.getItem('iphoneusername');
url: 'http://' + url + '.com/iphone/adddisplayapi.php',
data: "",
dataType: 'json',
success: function(data)
{
var id = data[0];
var name = data[1];
var pic1 = data[2];
document.write(name);
document.write("<br/>");
document.write(id);
document.write("<br/>");
}
});
});
</script>
Try:
$(function () {
var urlParam = localStorage.getItem('iphoneusername');
$.ajax({
url: 'http://' + urlParam + '.com/iphone/adddisplayapi.php',
data: "",
dataType: 'json',
success: function(data) {
....rest of your code
Hope it helps

ajaxComplete function "loader" running once

here is the code I'm using:
$(function() {
$(".fav").click(function() {
var page = $('#page').attr('value');
var user = $('#user').attr('value');
var time = $('#time').attr('value');
var info = "page="+ page +"& user="+ user +"& time="+ time;
$("#loading").html('<im g src="loader.gif" />');
$.ajax({
type: "POST",
url: "favorite.php",
data: info,
success: function() {
$("#loading").ajaxComplete(function(){}).slideUp();
$('#fav').fadeOut(200).hide();
$('#unfav').fadeIn(200).show();
}
});
return false;
});
});
</script>
<script type="text/javascript" >
$(function() {
$(".unfav").click(function(){
var page = $('#page').attr('value');
var user = $('#user').attr('value');
var info = "page="+ page +"& user="+ user;
$("#loading").html('<im g src="loader.gif" />');
$.ajax({
type: "POST",
url: "notfavorite.php",
data: info,
success: function(){
$("#loading").ajaxComplete(function(){}).slideUp();
$('#unfav').fadeOut(200).hide();
$('#fav').fadeIn(200).show();
}
});
return false;
});
});
Everything is working fine, it acts as a "like" "follow" button, the only problem is that the ajaxComplete() function only runs once.
Cheers!
$(function(){
$(".fav").click(function(){
var page = $('#page').attr('value');
var user = $('#user').attr('value');
var time = $('#time').attr('value');
var info = "page="+ page +"& user="+ user +"& time="+ time;
$("#loading").html('<im g src="loader.gif" />');
$('#follow').hide();
$.ajax({
type: "POST",
url: "favorite.php",
data: info,
success: function(){
$('#loading').empty();
$('#remove').fadeIn(200).show();
}
});
return false;
});
})();
same for .unfav

Resources