-1

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?

2 Answers 2

3
$("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

Sign up to request clarification or add additional context in comments.

1 Comment

@AndreasBonini the link of the demo has broken.
1

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

See the documentation — you need to specify a callback.

3 Comments

At least the alert window must popup. Nothing happening.
Where and how to specify callback?
The documentation that I linked to explains (and has examples)

Your Answer

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.