-1
<input id="Edit" name="Edit" value="Edit Record" type="button" onclick="$.get('fetchvalues.php', function(){myCallBack(ReadCookie('UpdateRecordID'));});" />

The ReadCookie function is of another JQuery script.

I want to pass the cookie value to the .php file.


This how I modified:

<td align="left">
 <input id="Edit" name="Edit" value="Edit Record" type="button" onclick="$.get('fetchvalues.php', ReadCookie('UpdateRecordID'), myCallBack);" />
</td>
<script type="text/javascript">
 $(document).ready(function(){
 $("#edit").click(function(){
 $.get('fetchvalues.php', function(){
 myCallBack(ReadCookie('UpdateRecordID'));
 });
 });
});
</script>

In the file: fetchvalues.php, I have written an echo statement to check whether AJAX call reaches there or not. But it is not calling that file. What's wrong?

Mick MacCallum
130k40 gold badges283 silver badges284 bronze badges
asked Dec 18, 2009 at 13:39
3
  • What does happen? What errors are reported? What makes you think it isn't working? Why are you reading a cookie using JS and including it in the query string instead of just letting the PHP program read the cookie itself? Commented Dec 18, 2009 at 13:51
  • Nothing. It just stays on the same page. Commented Dec 18, 2009 at 13:54
  • Of course it stays on the same page. It's a type='button' so it isn't going to submit a form, it's jQuery's $.get function, so that makes an HTTP request in the background. You haven't provided a callback function, so nothing is going to happen on the page when the response comes back. Commented Dec 18, 2009 at 14:28

1 Answer 1

4

Can't say from what you have just written.

I Would be interested to see more on: myCallBack, fetchvalues.php and ReadCookie

Certainly, start by making the JavaScript unobtrusive, and moving the click binding to the document ready function.

$(document).ready(function(){
 $("#edit").click(function(){
 $.get('fetchvalues.php', function(){
 myCallBack(ReadCookie('UpdateRecordID'));
 });
 });
});

Another problem. If you're wanting to pass data, then data is the second parameter on the get function. See the documentation here:

http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype

So, your function might be something like:

 $.get('fetchvalues.php', ReadCookie('UpdateRecordID'), myCallBack);

(p.s. check out the following for the click binding: http://docs.jquery.com/Events/click)

answered Dec 18, 2009 at 13:51
Sign up to request clarification or add additional context in comments.

3 Comments

How to execute the above code? I want it to be execute on the click of a button.
Suggest you read up on late binding. This line above helps you. $("#edit").click(function(){
Check out the get link on the post. jQuery.get( url, [data], [callback], [type] )

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.