0

I get Uncaught ReferenceError: bierta (or whatever the URL var is) is not defined when I run the AJAX call below. How can I fix this?

$.ajax({
  type: "GET",
  async: false,
  url: "get-single-marker.php",
  data: "slug="+<?php echo $_GET['gt']; ?>,
  dataType: "json",
  success: function(res) {
    data = res;
  }
});
1

4 Answers 4

0

Try

data: "slug=<?php echo $_GET['gt']; ?>,

or

data:{slug:"<?php echo $_GET['gt']; ?>"},

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

Comments

0

You want something like:

data: "slug="+<?php echo json_encode($_GET['gt']); ?>,

or

data: "slug=<?php echo $_GET['gt']; ?>",

or grab the gt from the query using JavaScript.

View source to see why your version doesn't work.

Regardless of the method you use, you need to make sure you properly validate/escape the input. $_GET is untrusted stuff.

Comments

0

You are assigning a variable to the element here, and that is why it give you an error.

Try Following Code.

data: "slug=<?php echo $_GET['gt']; ?>",

This should work

Comments

0

i hope this may work

data: { slug : <?php echo $_GET['gt']; ?> }  ,

quotes are not necessary

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.