>  기사  >  백엔드 개발  >  請問要如何把mui.ajax反回的數據加入網頁上

請問要如何把mui.ajax反回的數據加入網頁上

WBOY
WBOY원래의
2016-07-06 13:53:17998검색

在APP運行, 發生以下錯誤, 請問要如何把mui.ajax反回的數據加入網頁上

Uncaught TypeError: Property 'data' of object function (b,c){if(c=c||a,!b)return j();if("object"==typeof b)return i.isArrayLike(b)?j(i.slice.call(b),null):j([b],null);if("function"==typeof b)return i.ready(b);if("string"==typeof b)try{if(b=b.trim()......on at index2.html:38


function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {

var url = 'http://hktc.erufa.com/show.php'
mui.ajax(url,{

data:{
q:str
},

dataType:'html',
type:'get',//HTTP请求类型
timeout:30000,//超时时间设置为10秒;

success:function(data){

//服务器返回响应,根据响应结果,分析是否登录成功;
document.getElementById("txtHint").innerHTML = data;
},

error:function(xhr,type,errorThrown){

//异常处理;
console.log(type);
}

});

Start typing a name in the input field below:



First name:

Suggestions:


php code

header("Access-Control-Allow-Origin:*");
header("Content-type:text/html; charset=utf-8");

$a[] = "Anna";
$a[] = "Brittany";
$a[] = "Cinderella";
$a[] = "Diana";
$a[] = "Eva";
$a[] = "Fiona";
$a[] = "Gunda";
$a[] = "Hege";
$a[] = "Inga";
$a[] = "Johanna";
$a[] = "Kitty";
$a[] = "Linda";
$a[] = "Nina";
$a[] = "Ophelia";
$a[] = "Petunia";
$a[] = "Amanda";
$a[] = "Raquel";
$a[] = "Cindy";
$a[] = "Doris";
$a[] = "Eve";
$a[] = "Evita";
$a[] = "Sunniva";
$a[] = "Tove";
$a[] = "Unni";
$a[] = "Violet";
$a[] = "Liza";
$a[] = "Elizabeth";
$a[] = "Ellen";
$a[] = "Wenche";
$a[] = "Vicky";

// get the q parameter from URL
$q = $_REQUEST["q"];

$hint = "";

// lookup all hints from array if $q is different from ""
if ($q !== "") {

<code>$q = strtolower($q);
$len=strlen($q);
foreach($a as $name) {
    if (stristr($q, substr($name, 0, $len))) {
        if ($hint === "") {
            $hint = $name;
        } else {
            $hint .= ", $name";
        }
    }
}</code>

}

// Output "no suggestion" if no hint was found or output correct values
echo $hint === "" ? "no suggestion" : $hint;
?>

回复内容:

在APP運行, 發生以下錯誤, 請問要如何把mui.ajax反回的數據加入網頁上

Uncaught TypeError: Property 'data' of object function (b,c){if(c=c||a,!b)return j();if("object"==typeof b)return i.isArrayLike(b)?j(i.slice.call(b),null):j([b],null);if("function"==typeof b)return i.ready(b);if("string"==typeof b)try{if(b=b.trim()......on at index2.html:38


function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {

var url = 'http://hktc.erufa.com/show.php'
mui.ajax(url,{

data:{
q:str
},

dataType:'html',
type:'get',//HTTP请求类型
timeout:30000,//超时时间设置为10秒;

success:function(data){

//服务器返回响应,根据响应结果,分析是否登录成功;
document.getElementById("txtHint").innerHTML = data;
},

error:function(xhr,type,errorThrown){

//异常处理;
console.log(type);
}

});

Start typing a name in the input field below:



First name:

Suggestions:


php code

header("Access-Control-Allow-Origin:*");
header("Content-type:text/html; charset=utf-8");

$a[] = "Anna";
$a[] = "Brittany";
$a[] = "Cinderella";
$a[] = "Diana";
$a[] = "Eva";
$a[] = "Fiona";
$a[] = "Gunda";
$a[] = "Hege";
$a[] = "Inga";
$a[] = "Johanna";
$a[] = "Kitty";
$a[] = "Linda";
$a[] = "Nina";
$a[] = "Ophelia";
$a[] = "Petunia";
$a[] = "Amanda";
$a[] = "Raquel";
$a[] = "Cindy";
$a[] = "Doris";
$a[] = "Eve";
$a[] = "Evita";
$a[] = "Sunniva";
$a[] = "Tove";
$a[] = "Unni";
$a[] = "Violet";
$a[] = "Liza";
$a[] = "Elizabeth";
$a[] = "Ellen";
$a[] = "Wenche";
$a[] = "Vicky";

// get the q parameter from URL
$q = $_REQUEST["q"];

$hint = "";

// lookup all hints from array if $q is different from ""
if ($q !== "") {

<code>$q = strtolower($q);
$len=strlen($q);
foreach($a as $name) {
    if (stristr($q, substr($name, 0, $len))) {
        if ($hint === "") {
            $hint = $name;
        } else {
            $hint .= ", $name";
        }
    }
}</code>

}

// Output "no suggestion" if no hint was found or output correct values
echo $hint === "" ? "no suggestion" : $hint;
?>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.