Reputation: 11
just trying to pass some values from ajax to php file, but i am getting error function working ... kindly suggest me. my codes follows
<script>
function test(){
//alert("hello");
var myData ={
name : $("#name").val(),
email : $("#email").val(),
};
$.ajax({
url: "test1.php",
type: "POST",
dataType:'json',
data: {a: 155},
success: function(data){
console.log(data);
},
error : function(et){
console.log("failed");
alert(et);
});
return false;}
</script>
in console i can see vales are passing, i cant find the real solution for this help
Upvotes: 0
Views: 64
Reputation: 8338
$( document ).ready( function test(){
//alert("hello");
var myData ={
name : $("#name").val(),
email : $("#email").val(),
};
$.ajax({
url: "test1.php",
type: "POST",
dataType:'json',
data: {a: 155}})
.success (function(data){
console.log(data);
})
.error ( function(et){
console.log("failed");
alert(et);
})
});
You had some wrong syntax + you need to tell your jquery when to execute. I set it on $( document ).ready
you can modify it for onClick
or whatever you want. Ajax call is working tested it in my environment.
Upvotes: 1