-1

I want to get value in JavaScript using Ajax Call,
I am using the following code:

var value = $.ajax({
    type:"GET",
    url:"get_result.php",
    data:"{'abc':" + $abc + "}",
});

alert(value);

while I wrote following code in get_reult.php:

<?php
    echo $abc= "Working";
?>

Happy to know about good solution

1
  • Have a look at the jQuery tutorial to learn how to make Ajax calls with jQuery and process the response with the server: learn.jquery.com/ajax. The purpose of this tutorial is to help developers in exactly your situation. Commented Dec 26, 2013 at 8:13

3 Answers 3

1
$.ajax({
  url: 'get_result.php',
  type: 'GET',
  data: 'abc='+$abc,
  success: function(data) {
    //called when successful
    alert(data);
  },
  error: function(e) {
    //called when there is an error
    //console.log(e.message);
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

You're looking for the success parameter in your call:

<script>
$.ajax({
    type:"GET",
    url:"get_result.php",
    data:"{'abc':" + $abc + "}",
    success: function(result) {
        alert(result);
    }
});
</script>

Read more about AJAX calls with jQueryhere

Comments

0

The ajax call is asynchronous so that the result is probably not available when you call alert(value);

You will need to put this code into a success block.

$.ajax({
    type:"GET",
    url:"get_result.php",
    data:"{'abc':" + $abc + "}"
}).success (function(value) 
{
  alert(value);
});

Comments

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.