Jump to content

[SOLVED] Jquery for PHP MySQL?


Kane250

Recommended Posts

Hi,

 

I'm building an application that has multiple textareas on the page, and each textarea has buttons that either insert or retrieve data to MySQL from or to the textareas.  In order to not reset all the textareas on the page through standard PHP (and without going crazy with sessions), I wanted to use AJAX to make these requests.  I was told that using Jquery is much better for this, but am having a very hard time finding documentation that would show me how to use Jquery with pre-existing PHP and MySQL code.  I do not know Javascript, but could definitely follow instructions if a good tutorial was provided.  Does anyone have any references or links?  I've looked everywhere..

 

Thanks!

Link to comment
Share on other sites

Hey Kane,

 

If you are using a CMS, then you may have some issues with the "pre-existing" code, however not all CMS's are a PITA ;)

 

Basically you would need to edit the form, when you have a <textarea> box you would need to assign an ID to it, for example <textarea id="box1" name="box1">  you could then use ajax to use

getelementbyid('box1') or something similar to find the box that you need to "submit without refreshing".

 

You will need more than just an id and the 1 piece of code i've given you, i suggest looking at

 

http://www.malsup.com/jquery/form/

 

they are not using the "id" in the <form> tag. I hope this helps :) Remember to mark it Solved if it does

Link to comment
Share on other sites

Basically what I was saying is that, I have it set up already so that I can fill textareas with ajax, but what I need to do is have ajax or jquery connect to a php script that I have written to retrieve database info and return that to the textarea.

 

This would be done when I hit a submit button next to the textarea.  Does that make sense?

Link to comment
Share on other sites

Yea, I think that makes sense. Try something like this:

 

Javascript:

  // SUBMITTING UPDATE
		$('#submitConfirm').click(function() {
			      // if you need values from the form
                                        var val1 = $('#field1').val();

				$.ajax({
				   type: "POST",
				   url: "/includes/path-to-script",
				   data: val1+"&nextVar="+'sending a string',
				   cache: false,
				   dataType: "json",
				   success: function(data){
                                                        // all of the variables are from the json encode
				   		alert(data.response);
				   }
				});
		}); // END OF SUBMIT

 

<?php
// php script to return the json encoded variables.
$val1 = $_POST['val1'];
$str = $_POST['nextVar'];

// do something

$response = 'this is an fake example of your text.';

// return values
$arr = array ('response'=>$response, 'error'=>$error, 'errorMsg'=>$errorMsg);       // errors for displaying if there is an error
echo json_encode($arr); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.