By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,107 Members | 679 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,107 IT Pros & Developers. It's quick & easy.

Problem Debugging javascript/Ajax

P: 2
I am trying to write a simple Ajax application using SUSE 10.2, Apache, PHP and Javascript.

I want to click on a table header and do some processing to update the table. i have a function mySort which is called when you click on a table header. It sets some fields on the page and calls a second function which does the and the xmlHttp.onreadystatechange calles. everything works fine the first time I click on a header. The fields are updated, the table is updated, there are no error messages in the Firefox error console or the Firebug window. However If I click on a header a second time I get an error message that mySort is not a function.

I have tried everything I can think of to fix this problem. I even went back to an old copy and reapplied all of the changes one by one until it stopped working to make sure that is where the problem was. I have also tried returning the onclick property from the PHP script.

In the PHP script I look up the new information for the table and rerturn the formatted table minus the tables tags. I then add the Table tags and the header line in the Javascript. everything works fine and keeps working it I take out the onclick property.

Below is the Javascript I am having problems with. I have examined the HTML before and after running the mySort function and I can find no differences.

Expand|Select|Wrap|Line Numbers
  1. myTable = '<table border=1><tr><th>Sel</th>';
  2. myTable = myTable + '<th\ onClick=\"mySort(\'pri\', 1 );\">pri</th>';
  3. myTable = myTable + '<th>Date</th><th>Rqstr</th><th>Status</th><th>Desc</th></tr>';
  4. myTable = myTable + statusRSP;
  5. myTable = myTable  + '</table>';
  6. document.getElementById("Layer2").innerHTML = myTable;
layer2 holds the table and nothing else.

Thanks for any suggestions. If there is a better way to return the table from the PHP script please let me know.
May 7 '07 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 16,027
You don't need to escape the double quotes within single quotes.
May 8 '07 #2

P: 21
just a tip: you can do xxx += zzzzz, saves some space
May 8 '07 #3

P: 2
Thanks for the replies. I removed the extra backslashs and tried again with the same results. Then I had the bright idea to rename the function. Once I renamed the function it started working. I am not sure what it was conflicting with but atleast it is working now.

Thanks again.
May 8 '07 #4

Expert Mod 15k+
P: 16,027
Glad you got it working.
May 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.