0
$("a.star").click(function(e){ 

e.preventDefault(); 

var dataID = $(this).data('id');

$.ajax({
    type: "POST",
    url: "/engine/save.php",
    data: "id=dataID"
    success: {

         alert("FFS WORK " + data);

    }
});
return false;
});


<a href="javascript:void(0)" data-id="7" class="star">test</a>

How can I send data-id to save.php (/engine/save.php?id=7) successfully? Tried just about everything and no luck.

0

3 Answers 3

4

just with

data: { id : dataID },

the benefit of using an object (instead of a string concatenation) is that you don't need to worry to escape the value passed along with the ajax call

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

3 Comments

I changed the data to this but it's still not processing anything to /engine/save.php. I wonder if there is an error in my syntax?
you should also add a comma , before success: (look at your js console)
Found it just after posting. Tar. :P
2
url: "/engine/save.php?id=" + dataID 

Comments

1

First of all you should understand how to concatenate a string with a js variable. You should use + operator to concatenate a string and a js variable.

Use this

data: "id=" + dataID;

You can also send it as an object jQuery will take care of attaching it to the request.

data: { id: dataID }

1 Comment

I see. This wasn't the actual problem with my code though. Even when changed to these the data will not be passed to /engine/save.php. :( Is there a problem with my syntax at all?

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.