RKh
RKh

Reputation: 14159

Calling jquery function

My code is like this:

<script type="text/javascript">
    $(document).ready(function(){
    $("Edit").click(function(){
    $.get('fetchvalues.php');
        });
    });
</script>

<input id="Edit" name="Edit" value="Edit Record" type="button" onclick="$.get('fetchvalues.php');" />

In the file "fetchvalues.php", I have written some code along with the javascript alert window to see whether the control reaches there. But nothing is happening.

Am I calling correctly?

Upvotes: -1

Views: 205

Answers (2)

Andreas Bonini
Andreas Bonini

Reputation: 44832

$("Edit").click(function(){

This should be:

$("#Edit").click(function(){

And if you have that you don't need it again in the click="" HTML attribute.

Also try your debugging alert with:

$.get('fetchvalues.php', null, function() { alert('test'); });

Also it's not very clear to me where you put the alert() in your original code. In the HTML code outputted from fetchvalues.php ? If yes then it will never be executed; you would have to load the file by adding a directive to your html file through javascript.


EDIT: Answering question asked in the comments here for better formatting.

When we call "fetchvalues.php", how to know it is being called.

You could temporarily erase all the code in fetchvalues.php and replace it with:

<?php print "Whatever you want"; ?>

After that, replace your $.get with:

$.get('fetchvalues.php', null, function(php_output_text) { alert(php_output_text); });

That should alert() "Whatever you want"!


Live demo: http://koper.wowpanda.net/so.html

Upvotes: 3

Quentin
Quentin

Reputation: 944568

You are making an HTTP request but not doing anything with it.

See the documentation — you need to specify a callback.

Upvotes: 1

Related Questions