I have written code that form checks and if all is good passes user input data to ajax so that the database table can be written to. While trying various browsers I am successful at writing to the table with chrome and iexplorer but nothing is written in firefox and no php errors are thrown.
Can anyone see any reason why the following ajax call is not successful with firefox?
$.ajax({
type: "POST",
url:"ajax/ajax_repSub.php",
data: {tDate: tDate, tSpecies: tSpecies, tSqrNum:tSqrNum, tLat:tLat, tLng:tLng, tCond:tCond, tNum:tNum, tHab:tHab, tBehav:tBehav, tReg: tReg, tStage: tStage},
dataType: "text",
cache: "true",
success: function(msg,string,jqXHR){
$("#results").html(msg+string+jqXHR);
}
});
Related
I guess I'm not up-to-date or am missing something really simple.
I have the javascript code below, which uses ajax to connect to an external php file which reads the form post'd variables and pulls pricing from a sql database and returns the price, which is updated on the current page. The machine I am testing on uses Windows 7 and the latest version of Chrome browser. The ajax call ALWAYS works. I was in a different office yesterday and tested the code on a Windows 10 machine running the latest Chrome browser and the ajax call seems to never work and no price is updated. I also tried the latest Internet explorer browser on the same Windows 10 machine and it did NOT work. I found another Windows 7 machine at the same location using Chrome and it worked fine on it. What's even crazier is this morning, I tried the code on a Windows 10 machine running the latest Chrome and the first time the page loaded it worked but then quit again.
I keep checking the code and don't see anything, as it works fine on some machines. Any ideas or thoughts would greatly be appreciated.
I am using jQuery v1.12.4. I thought maybe this might have an issue so I tried using 3.1.1 even and nothing changed.
What am I missing? How would I be able to debug the ajax call to see what is actually happening on the computer that it isn't working?
THE JAVASCRIPT CODE:
<script type='text/javascript'>
// Monitor changes to Quantity form field
$('#Quantity').on('keyup', function(event) {
$.ajax({
url: 'updatePrice.php',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: $('#OrderDetails').serialize(),
datatype: 'json',
success: function(response) {
$("#showPrice").text('$' + response);
}
});
});
function updatePrice() {
$.ajax({
url: 'updatePrice.php',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: $('#OrderDetails').serialize(),
datatype: 'json',
success: function(response) {
$("#showPrice").text('$' + response);
}
});
}
</script>
THE SHORTENED HTML CODE RELATED TO THE JAVASCRIPT:
Quantity<br><input type="text" name="Quantity" id="Quantity" class="textWidth2" value="">
<img src="images/B&WSelected.png" id="BWimage" onclick="changeImage3(); updatePrice();">
<div class="border-top-color quote_panel">
<span class="quote_title">Your Price:</span>
<span id="showPrice" class="quote_price">$0.00</span>
</div>
I finally figured out what was causing the problem I believe. I think it is both 'crossdomain requests' related and encoding issues.
I edited the ajax call by removing the full url (http://www....) from url: and only left the file name and I removed the line
contentType: 'application/json; charset=utf-8',
from the code and now everything seems to work perfectly
function updatePrice() {
$.ajax({
url: 'updatePrice.php',
type: 'POST',
data: $('#OrderDetails').serialize(),
datatype: 'json',
success:function(response){
$("#showPrice").text('$'+response);
}
});
}
download jQuery CDN – latest stable version
I am making an AJAX request from one page to another webform (*.aspx). I am passing Japanese text as description from ajax and this is working fine in all browsers except in IE. I even added Japanese language (ja-JP) to the browsers languages with an assumption that IE will support it but I failed.
Need some work around for this... Waiting for your help.
Below is my ajax code
$.ajax({
url: urlAssetUpload + uploadVars,
type: 'POST',
processData: false,
contentType: "charset=UTF-8",
data: encodeURIComponent(formDatz)
});
I'm using cordova and dust.js (HTML templating) in my app. I make Ajax requests that return json objects.
Platforms the App is working on:
--Android browser,FF, chrome and Apk
--iPhone
--PC firefox and IE11 (1 out of 3 pc's wasn't able to make the ajax calls too)
--Windows phone 8 app
Problem:
When I try the windows phone 8 internet explorer, no ajax calls succeed in my app.
Details and solutions I tried
1- The json response is returned correctly as I checked the server log that the ajax call is made to...
2- This problem happens in GET requests as well as POST requests...
3- The ajax is not excuting neither the done nor the fail:
$.ajax({
type: httpMethod,
url: host + url,
data: data,
async: asyncFlag,
dataType: "json",
error: errFn,
dataFilter: dataFilter,
success: (successFn),
timeout: 60000
}).done(function(msg) {
alert( "done" );
}).fail(function() {
alert( "error" );
});
4- I tried adding cache:false in the above request, didn't solve the problem.
I have this javascript in my page.
function save() {
// submit the dataform
s = document.dataform.action.split('?');
d = s[1]+'&'+$("#dataform").serialize();
$.ajax({
url: s[0],
data: d,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: handleReply
});
}
It is called when I want to submit the form (and handle the reply using AJAX). However although $_SERVER['REQUEST_METHOD'] is indeed "POST" when it arrives at the server, all the data arrives in the $_GET variable! :(
I have screens with more than 2K of data so I have to find how to POST the data using the normal (and unlimited) POST method.
I had a version with the url and data lines as
url: document.dataform.action,
data: new FormData(document.dataform),
This worked superbly with some data arriving from the action in $_GET and the rest from screen fields arriving in $_POST. Then I tested it using IE8 and IE9, which don't support FormData.
Can anyone suggest how I can modify the code to work in IE8 and IE9 and use POST transfer logic.
Thanks
I'm making a dynamic webpage which retrieves lots of data from a database very frequently, like at least every 3 seconds.
I tested my webpage and database locally by using XAMPP. It works perfectly. However, it turns to be very slow after I upload everything to 000webhost (my free account). My webpage even freezes (I cannot scroll the page, not even doing anything but wait for the data to be transferred.) when retrieving the data.
I used a setTimeout function which called several ajax commands to read data from my database. I have optimised the data capacity already, but the page still freezes. I also tried to disable most of the ajax commands and only left one. When loading, the page freezes just as a blink, but anyhow it still freezes...
Most of my ajax commands are like below which simply retrieves data from my database and updates the related fields on my webpage. Some ajax commands uses $.parseJSON() because I need the whole row from a table.
$.ajax({
type: "GET",
url: "get_balance.php",
data: {wherematch: localStorage.login_user},
dataType: "html", //expect html to be returned
async:false,
success: function(response){
document.getElementById('balance').innerHTML = response;
}
});
Can anyone provide some suggestions how to solve this issue? Should I pay and get a better account?
Thanks.
to have an ajax refreshing every 3 s, your javascript & ajax must be like this:
function get_data(){
$.ajax({
type: "GET",
url: "get_balance.php",
data: {wherematch: localStorage.login_user},
dataType: "html", //expect html to be returned
success: function(response){
document.getElementById('balance').innerHTML = response;
setTimeout(get_data(),3000);
}
});
}
get_data();
Put setTimeout() function inside the ajax. You will not get freeze because we don't set async as false