Ajax request issue with jQuery
Solved
pignou0
Posted messages
55
Status
Member
-
pignou0 Posted messages 55 Status Member -
pignou0 Posted messages 55 Status Member -
Hello,
I'm trying to make an Ajax transfer using jQuery, but it doesn't seem to be working and none of the alerts before the $.ajax are triggering either. If you know why, I would like to know, considering that I'm completely new to jQuery and Ajax. Thank you.
Here is my code:
Thank you in advance
Configuration: Linux / Firefox 12.0
I'm trying to make an Ajax transfer using jQuery, but it doesn't seem to be working and none of the alerts before the $.ajax are triggering either. If you know why, I would like to know, considering that I'm completely new to jQuery and Ajax. Thank you.
Here is my code:
var arrayligne=document.getElementById("montableau").rows; var arraycolonne=arrayligne[theId].cells; var chaine=arraycolonne[10].innerHTML; var indexdebut=chaine.indexOf(';')+1; var longueur=chaine.lastIndexOf('<'); longueur=longueur-indexdebut; chaine=chaine.substr(indexdebut,longueur); var chaine2=arraycolonne[11].innerHTML; var indexdebut=chaine2.indexOf(';')+1; var longueur=chaine2.lastIndexOf('<'); longueur=longueur-indexdebut; chaine2=chaine2.substr(indexdebut,longueur); var n=parseFloat(chaine)+parseFloat(chaine2); alert(n); arraycolonne[10].innerHTML=n; alert("change OK"+arraycolonne[10].innerHTML); $.ajax({ url : 'updateBDD.php', // The targeted resource type : 'POST' // The type of HTTP request. data : 'newchiffre=' + arraycolonne[10].innerHTML; }); Thank you in advance
Configuration: Linux / Firefox 12.0
2 answers
-
Hello,
I recommend you start by updating your Firefox and downloading Firebug.
This way, you'll have a console that will tell you when you have bugs in JavaScript, and you can also display information such as your variables using the function:
console.log(variable);
No more need for alerts, and you'll be informed of any possible errors.-
-
-
Yes, I finally managed to modify the body with jQuery so it works, but the console doesn't show me any errors, even though I requested it to stop at each error :s.
I tried with a post:
$.post("updateBDD.php", { newchiffre: arraycolonne[10].innexHTML }, function(data){ alert("Data Loaded: " + data); } );
And I have the pop of the data at the end which returns me a lot of pretty ugly lines of code. -
Actually, I had an error (corrected):
The character encoding of the HTML document has not been declared. The document will be displayed with incorrect characters for some browser configurations if the document contains characters outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.
-
-
Well, I'm at this point:
My ajax executes and apparently according to firebug and my http headers I pass into my php file updateBDD.php but I don't think the update is happening at all... And I don't know why, any idea?
My Ajax post:$.post("updateBDD.php", {newchiffre: arraycolonne[10].innerHTML }, function(data){ alert("Data Loaded: " + data); } );
My Php script for update:
<? require 'bin/params.php'; mysql_connect($host,$user,$password); mysql_select_db($base); $montant=$_POST['newchiffre']; echo $montant; $query = "UPDATE TRANSACTION SET MONTANT_HT ='$montant'"; mysql_query($query); mysql_close(); ?>
Thanks in advance