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
$( 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.