Ajax request issue with jQuery

Solved
pignou0 Posted messages 55 Status Membre -  
pignou0 Posted messages 55 Status Membre -
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:

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

ThEBiShOp Posted messages 9307 Registration date   Status Contributor Last intervention   1 605
 
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.
0
pignou0 Posted messages 55 Status Member 2
 
Thank you, I will try to see with this tool, but apparently it comes from my use of Jquery; as soon as I use any Jquery function, nothing happens anymore, otherwise it works.
0
ThEBiShOp Posted messages 9307 Registration date   Status Contributor Last intervention   1 605
 
The console will immediately tell you what is wrong.

Have you correctly declared the jQuery library?
0
pignou0 Posted messages 55 Status Member 2
 
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.
0
pignou0 Posted messages 55 Status Member 2
 
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.
0
pignou0 Posted messages 55 Status Member 2
 
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
0
pignou0 Posted messages 55 Status Member 2
 
I found out that you need to use a GET instead of a POST; I don't really know why, but that's how it is ^^'
0