![]() |
Ajax/Jquery with PHP/SQL
I'm losing my mind trying to understand how ajax/jquery work. My site is based around phpbb, although I don't think that matters much for this. All I want, is for a js function (below)
Code:
function RoSave(frm)PHP Code:
Code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>I've tried jquery as well Code:
$.post('easterdraw.php', $("#form").serialize();, function(data){ |
If you use a type "POST" request, the parameters handed over to PHP will be available in the $_POST associative array. So the image_data parameter will be available as $_POST["image_data"] and not $image of course.
|
right now the php looks like this (and still doesn't work).
PHP Code:
|
Where does file_get_contents come from? It is a PHP method to open and read a file from the server(!). But image_data is just a string containing the image data as a data URL (base64 encoded).
And "save" doesn't seem to be a parameter, neither is "&title". You have three parameters "image_data", "author" and "title". The & ampersand is just a separator and will be automatically removed from PHP when processing the query string. |
I've never tried to write something in Ajax or Jquery before, I'm really just throwing things against the wall to see what sticks at this point.
Thanks for the variable info, I'll fix them now. I think the bigger issue (beyond the misnamed variables) is the fact that *nothing* is happening when I click save. I tried changing the php file to nothing but echo "yes" and it did nothing. Somewhere along the way, the ajax is not meeting up with the file its suppose to be calling (which is in the root directory), or the function isn't coming back true, or something. :S I can't start debugging the code until it actually starts to do what its suppose to do. Right now it does absolutely nothing. |
Ok, so back to the basics:
1. Any syntax errors (look at the Javascript Console) ? 2. Did you include jQuery? 3. You used encodeURIComponent on one parameter, which is correct but you should use it on every parameter (also title and author) 4. Where did you define the variable canvas? |
Quote:
2. I gave up on the Jquery, right now its just using ajax, php and html. 3. Okay. 4. var roCanvas={}; is at the top of the js file. Edit: I edited the first post with the updated codes. Still not getting any sort of reaction from the script (it doesn't even close the popup or change the url address when I click save). *sigh* |
1. I wasn't talking about PHP errors but rather about Javascript errors. Please take a look at your Javascript console
2. You need jQuery for $.ajax() ! 4. So you defined "roCanvas" but in your code example you use the variable "canvas". Where is it defined? New: {ROOT_PAHT} should probably be {ROOT_PATH} |
Quote:
2. Ack! Do I need to use $.post jquery or am I totally off track already? 3. var canvas = document.getElementById('RoCanvas'); a few lines beneath the other one. |
2. I mean, do you have a line like this?
Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> |
Yes.
Code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> |
Are you still struggling with this? See the code from our "Draw a Robot" app (I'm the creator or RoCanvas):
Code:
function saveRobot(frm) |
YES please do share PHP!!!
Sorry to exhume this thread but I have been trying to figure this one out too. How do you define a variable based on the ajax data?
|
thighmister, You really should start your own thread. Reviving a 9 month old one will confuse the people that read the first post and try to answer that persons question, skipping yours.
Most of the time (very close to all the time but I just know someone has an exception to that, they always do) The return (data via jquery, that's what the top post is using) of an ajax call is a php script to write information to the screen, not to send variables to javascript. The return can be written to a <div> that was created to show the data or it can create it's own div. Or it can replace or add to the contents of something already on the page. Changing the page without refreshing the page is what ajax is all about. |
| All times are GMT +1. The time now is 10:17 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.