According to same origin policy, I can't use regular json for ajax call, so I use jsonp instead. I have a simple input field and class name is "newCaller". In my js file
$(document).on("blur", ".newCaller", function(){
var name = $(this).val();
var tel = $(this).siblings(".tel").text();
//console.log(name+tel);
$.ajax({
type: 'GET',
url: 'xxx.xxx.com/phpFunc.php',
data: ({ 'name' : name, 'tel' : tel }),
dataType: 'jsonp',
//I tried success instead of jsonpCallback as well
jsonpCallback: function(data){
console.log(data);
}
});
});
And here is the php:
<?php
$name = $_GET['name'];
$tel = $_GET['tel'];
echo $name.$tel;
?>
When the ajax function is triggered, the value from the field is undefined. For example, I type "test" into text field and trigger the function, please see following image (sorry for the black line, privacy policy)
I use success to callback and returns almost the same thing, "xxx is not defined". Could someone tell me how to fixed it? Thank!