fvcxvcxv
fvcxvcxv

Reputation: 85

Send data to php page with ajax

I have a bug actually with this code.

My JS code is the following:

<script>
var card_Name = "Tour Eiffel";
</script>

I send the data in ajax:

var myDatas = { card_Name: card_Name };

$.ajax({
    type: "POST",
    url: "saveContent.php",
    data: myDatas,
    cache: false,
    contentType: false,
    processData: false,
    success:  function(data){
      alert(data);
    }
}); 

In my PHP i get the element like this:

print_r($_POST['card_Name']);

But nothing is shown in the XHRs parts of my console...

Any idea why ?

Thanks.

Upvotes: 0

Views: 30

Answers (1)

weelDaw
weelDaw

Reputation: 90

Do this in HTML or PHP File .

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
    $(function(){

        var card_Name = "Tour Eiffel";
        var myDatas = { card_Name: card_Name };

        $.ajax({
            type: "POST",
            url: "saveContent.php",
            data: myDatas,
            cache: false,
            success:  function(data){
           alert(data);
          }
       });
    })
</script>

Don't include this in your ajax

contentType: false,
processData: false,

Upvotes: 1

Related Questions