Jump to content

Nanonano

Members
  • Content Count

    14
  • Joined

  • Last visited

Community Reputation

1 Neutral

About Nanonano

  • Rank
    Newbie
  1. Ok, thank you. I changed that line of code to: document.getElementById("new_svg_shape").data=xmlhttp.responseXML; which got rid of the error. Great!However nothing happens. The code returned from the UpdateSVGPage.php file is correct (when I check it in Firebug), but nothing happens on the image itself. The code doesn't render. I tried to use the <svg> tag instead of the <g> tag, where the code is returned to, but still nothing happens.Any ideas?
  2. Hello, and thank you for answering. As you suggested, I added content type to UpdateSVGPage.php, like this: <?php header('Content-Type: image/svg+xml'); //get the q parameter from URL $q=$_POST["input"]; echo "<rect x=\"1200\" y=\"233\" width=\"80\" height=\"20\" fill=\"blue\" />"; ?> Then I checked in "Firebug" what happens when the ajax_function() is called:- The parameter which is sent to the UpdateSVGPage.php file is correct, if I send it.- The response headers content type is image/svg+xml, and the request headers content type is text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 (whatever that means)- The response is <rect x="1200" y="233" width="80" height="20" fill="blue" /> which is correct.- Then it complains about an error on this codeline: document.getElementById("new_svg_shape").firstChild.data=xmlhttp.responseXML; which is located in the SVGPage.php file. In aid for more info, I checked it also in chromes debugger, and that states that: - Uncaught TypeError: Cannot set property 'data' of null - xmlhttp.onreadystatechangeon the same line of code as Firebug whined about. Could someone help me with this debugging-info? I am not good at interpreting it.
  3. Hello. I am very stuck at one point in my web-page project, and I hope that anyone of you can help me. In short, I'm trying to achieve an AJAX-like effect in a SVG-document. What I mean is that when the SVG-document (in my example below called SVGPage.php) has finished loading and is just sitting there waiting, I want to use AJAX on the click of an SVG-element (in my example the rectangle) to send a request to an external PHP-file (in my example called UpdateSVGPage.php).This "UpdateSVGPage.php" is building up SVG-code based on information from a database, and it will echo it back to the SVG-document via the same AJAX-request.The newly received SVG-code is deployed to a specific element in the SVG-code (in my example a <g>-element with the id="new_svg_shape"), and the new shape is instantly rendered and view-able on the SVG image.When the user clicks on the specific shape once again, the whole process should be repeated (meaning that a change in the database would create a different SVG-image). I have made an attempt below (which is not working), and I hope that my intentions are understandable. index.php <?phpsession_start();?><!DOCTYPE html><html> <head> </head> <body> <embed src="SVGPage.php" type="image/svg+xml" width="1000px" height="1000px"/> </body> </html> UpdateSVGPage.php <?phpsession_start(); //get the q parameter from URL $q=$_POST["input"]; echo "<rect x=\"1200\" y=\"233\" width=\"80\" height=\"20\" fill=\"blue\" />"; ?> SVGPage.php <?phpsession_start();header('Content-Type: image/svg+xml');print('<?xml version="1.0" standalone="no"?>');?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="Library.js"/> <script type="application/ecmascript" > <![CDATA[ function ajax_function(){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function(input){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById("new_svg_shape").firstChild.data=xmlhttp.responseXML; } } xmlhttp.open("POST","UpdateSVGPage.php?q="+input,true); xmlhttp.send(); } ]]> </script> <rect height="100" width="100" fill="blue" onclick="ajax_function()"> </rect> <g id="new_svg_shape" /> </svg> A big thanks to anyone who might help me !
  4. You were right, innerHTML does not work in SVG. I changed the code in my last post above, so now it's working when I return the AJAX-stuff to a SVG-text-tag. What I now need is a way to return pure SVG-code via AJAX, and put it somewhere inside the SVG-tags.So that new shapes are created after the AJAX-call.I've made an attempt under, but it doesn't seem to work as expected. I hope that someone can correct me. drawing.svg <?phpsession_start();header('Content-Type: image/svg+xml');print('<?xml version="1.0" standalone="no"?>');?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="library.js"/> <script type="application/ecmascript" > <![CDATA[ function ajax_function() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("display_data").firstChild.data=xmlhttp.responseText; } } xmlhttp.open("GET","connect_to_database.php",true); xmlhttp.send(); } ]]> </script> <rect id="trigger" width="100" height="50" fill="black" onclick="ajax_function()" /> <g id="display_data" /> <!-- Somehow the pure SVG-code returned from connect_to_database.php should be put in here --> </svg> connect_to_database.php echo "<rect x=\"100\" y=\"100\" width=\"50\" height=\"20\" /> ";
  5. Hello, and thank you for answering so fast! That could be an option when a shape is clicked it initiate a JS-function which took care of the AJAX business, but I think I tried that and couldn't figure out how to put the received data from the database into the right element. Could you help me with that line of code? *** Edited later, now working *** index.php <?php session_start(); ?><!DOCTYPE html><html> <head> </head> <body> <embed src="drawing.php" type="image/svg+xml" width="1000px" height="500px"/> </body></html> drawing.svg <?phpsession_start();header('Content-Type: image/svg+xml');print('<?xml version="1.0" standalone="no"?>');?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="library.js"/> <script type="application/ecmascript" > <![CDATA[ function ajax_function() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("display_data").firstChild.data=xmlhttp.responseText; } }xmlhttp.open("GET","connect_to_database.php",true);xmlhttp.send();}]]></script> <?php /* some PHP code is building the SVG-image here */ ?> <rect id="trigger" width="100" height="50" fill="black" onclick="ajax_function()"> <animateTransform id="scaledown" attributeName="transform" attributeType="XML" type="scale" from="1" to="3" begin="display_data.click" dur="1s" additive="replace" fill="freeze"/></rect> <text id="display_data" y="100" width="100" height="50" fill="black" ></text> </svg>
  6. Ok friends: I'm totally stuck, and I desperately need some guidance from you professionals. For the last couple of months I've been working on a web-page project.This is what I've got so far: - I've got a HTML5 page (index.php)- In this HTML5 page, I've got an embedded SVG-file, which is converted to a PHP-file (drawing.php)- It is converted to PHP, because it uses some data in a database to decide what the SVG-image should look like.- In this SVG-file, a PHP-script builds some graphics, and applies some animations to it.- The SVG-file also has a javascript-library attached to it, which I need for zooming and panning the SVG-image. Everything is fine so far, however now starts the problems:I've got some other data in my database, which is supposed to be displayed on the SVG-image only after the user clicks on a specific shape belonging to the SVG-image. The only possible way I could imagine this to work would be to use AJAX, however I have no idea how to use AJAX together with an embedded SVG-file.Googling for days hasn't help me too much either. I would be very grateful to anyone who could provide some help.
  7. I found a solution: SVGimage.html <?phpsession_start();$FirstName = $_SESSION['GameName'][0];$LastName = $_SESSION['GameName'][1];$FullName = $FirstName . " " . $LastName;header('Content-Type: image/svg+xml');print('<?xml version="1.0" standalone="no"?>');?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="Library.js"/> <?php echo "<rect x=\"50\" y=\"70\" rx=\"10\" ry=\"20\" width=\"90%\" height=\"150\" fill=\"red\" /> ";?></svg> The <xml>-tag has to be wrapped in PHP's print() function. But thanks for all the help boen_robot !!
  8. Hey.Yes, the server is running php, and I have used it with great success earlier, for example for retrieveing data from a database.I tried your suggestion to view source (good tip btw), and no php-code is shown there.What it says there is: <b>Parse error</b>: syntax error, unexpected T_STRING in <b>/www/clanteam.com/b/e/u/beurocity/htdocs/Gamepage/BuildCity.php</b> on line <b>8</b><br />
  9. Thanks again.So it should be like this? index.html <embed src="SVGimage.php" type="image/svg+xml" width="500" height="400" /> SVGimage.php <?php session_start(); $FirstName = $_SESSION['GameName'][0]; $LastName = $_SESSION['GameName'][1]; $FullName = $FirstName . " " . $LastName; header('Content-Type: image/svg+xml');?><?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="Library.js"/> <?php echo "<rect x=\"50\" y=\"70\" rx=\"10\" ry=\"20\" width=\"90%\" height=\"150\" fill=\"red\" /> "; ?></svg> For some weird reason both IE and Chrome is complaining about a syntax error on line 8 (where the <xml>-tag is).I could understand why line 8 had an error earlier (since I had forgotten the <!DOCTYPE svg PUBLIC ....> tag)Firefox still wants to install a plug-in. I tried again to remove everything but the src="SVGimage.php" from the <embed> -tag.I also removed all the four "session"-lines from SVGimage.php, however then IE and Chrome were complaining about the same line where the <xml>-tag is.Any more ideas? I am really lost here. Thank you so much for helping.
  10. Thank you so must for answering. I tried your advice.In index.html I write the embedding with a php-extension, like this: <embed src="SVGimage.php" type="image/svg+xml" width="500" height="400" /> And my SVGimage.php looks like this: <?php session_start(); $FirstName = $_SESSION['GameName'][0]; $LastName = $_SESSION['GameName'][1]; $FullName = $FirstName . " " . $LastName; header('Content-Type: image/svg+xml');?><?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="Library.js"/><?php echo "<rect x=\"50\" y=\"70\" rx=\"10\" ry=\"20\" width=\"90%\" height=\"150\" fill=\"red\" /> ";?> </svg> However, when I run the page like this, my Firefox want to install a plugin, and chrome complains about a syntax error on line 8 in SVGimage.php I tried to remove everything but src:"SVGimage.php" from the embed tag.I tried to remove the four "session"-lines from the beginning of the SVGimage.php.I also tried to use PHP's "include"-function, in case that was what you ment.Unfortunatly, none of the above worked. Any more help is still appreciated.
  11. I have included a SVG-file into the html-page with the embed-tag, like this: index.html <!DOCTYPE html><html><head> <script type="text/javascript" src="jquery-1.7.1.js"/> function AJAX(){ $.post("UpdatePage.php",function (PhpParameter){ $("#SVGfile").html(PhpParameter); });} </head> <body> <div style="height:50px;width:50px;background-color:black;" onclick="AJAX()"/> <embed src="SVGimage.svg" type="image/svg+xml" /></body></html> The SVG-file looks like this: SVGimage.svg <?xml version="1.0" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script type="text/ecmascript" xlink:href="Library.js"/> </svg> The Library.js -file contains a nessicary library to zoom and pan my SVGimage.svg document. Library.js uses the XML-DOM. I use jQuery's POST method together with a PHP-file, which retrieve data from the database and parse it back to the html-file. The problem is:I have stored information in a MySQL database telling what the SVG-picture should look like. How can I transfer this information into the embedded SVG-file? Unfortunatly, I can't used <svg> tags directly in the HTML-file, because the Library.js file is written for the XML-DOM. I didn't write it, and I'm not good enough to convert it into using the HTML-DOM. Any help is very welcome! This has turned out to be a huge headache.
  12. Hello again. I found a pretty well working solution to the problem by using the onclick-event: <html><head><script type="text/javascript" src="jquery-1.7.1.js" /> /* Including the jQuery library */<script type="text/javascript">function AjaxFunction(AjaxParameter){$.post("UpdatePage.php", /* a POST request is sent to the file UpdatePage.php , */ {contentVar: AjaxParameter}, /* and the variable AjaxParamter is passed to UpdatePage.php . */function (data){ /* When complete, */$("#AjaxResponse").html(data); /* put the response in the div with id="AjaxResponse" . */});}</script></head><body><div id="TriggerA" style="background-color:green;width:80px;height:60px;" onclick="AjaxFunction('A')" /><div id="TriggerB" style="background-color:red;width:80px;height:60px;" onclick="AjaxFunction('B')" /><div id="AjaxResponse"></div> /* The AJAX response is put here. */</body></html> <?php $q=$_POST["contentVar"]; if ($q=='A') {echo "You used TriggerA";} else if ($q=='B'){echo "You used TriggerB";}?>
  13. Hello everyone. I was wondering if some of you might help a beginner with an issue concerning AJAX with jQuery 1.7.1 and an external PHP-file. I want to have a div, which by clicking on it will work as a trigger for an ajax-request to a PHP-file.Then I want to have second div, which by clicking on it will also work as a trigger for an ajax-request, however it gets a different response from the PHP-file. In other words, the response from the PHP-file should depend on which of the two div's was actually clicked. I have done an attempt as shown below.I know that it's missing a way to give my paramter (AjaxParameter) the correct nodevalue, depending on which of the divs was clicked.That is also what I am asking your help for. Apologies for my English, I hope that you understand. So, this is my html-file: <html><head> <script type="text/javascript" src="jquery-1.7.1.js" /> /* Including the jQuery library */ <script type="text/javascript"> var AjaxParameter /* The paramter which I want to pass to UpdatePage.php */ $(document).ready(function (){ $("#TriggerA, #TriggerB").click(function(){ /* If either TriggerA or TriggerB is clicked, */ $.ajax( url:"UpdatePage.php", /* an AJAX request is sent to the file UpdatePage.php , */ type: POST, data: AjaxParameter, /* and the variable AjaxParamter is passed to UpdatePage.php . */ success: function (result){ /* When complete, */ $("#AjaxResponse").html(result); /* put the response in the div with id="AjaxResponse" . */ }); }); }); </script></head> <body> <div id="TriggerA" value="A" style="background-color:green;width:80px;height:60px;" /> <div id="TriggerB" value="B" style="background-color:red;width:80px;height:60px;" /> <div id="AjaxResponse"></div> /* The AJAX response is put here. */ </body></html> This is my UpdatePage.php file: <?php $q=$_POST["AjaxParameter"]; if ($q=='A') {echo "You used TriggerA";} else if ($q=='B'){echo "You used TriggerB";}?>
×
×
  • Create New...