donpvtzuux37724 2013-09-10 13:20
浏览 36
已采纳

Jquery $ .ajax json与getjson格式

I have a ajax call with json like this to get my data from php code and then display it in my page:

      function get_customerdata(custID){

        var serviceURL_customer = serviceURL + 'getcustomer.php';

        $.ajax({
            type: "GET",
            url: serviceURL_customer,
            async: false,
            data: {id : custID},
            dataType: 'json',

            success: onSucess_displaycust


        });

        return false;

    }

    // --------------------------------------------------
        function onSucess_displaycust(data)
    {

        var customer = data.item;

        $('#custname1').text(customer.Name1);

       ... // other code

    // --------------------------------------------------
    // PHP code

       $customer = $stmt->fetchObject();  

         ...

       $clean = utf8_string_array_encode($customer);

       echo '{"item":' . json_encode($clean) .'}'; 

       ...

I want to put the variable

customer.Name1

in a div selector. This doesn't work. When i fetch the same data with the same php-script with $.getjson it is working fine without problems. I have to use $.ajax cause of syncron fetching data. Can anybody help to solve my problem?

This is a extraction of my json data:

 //------------------------------------------

        //json data

           1.   item: {ID:10011, UserID:XXX, Passwort:XXX, Name1:Bike Sport, Name2:XXX,…}

                 1. Name1: "Bike Sport"

This is the exact response of my json-data:

{"item":{"ID":"10011","UserID":"XXX","Passwort":"XXX","Name1":"Bike Sport", ...
  • 写回答

1条回答 默认 最新

  • doulao2128 2013-09-10 21:23
    关注

    Have you looked at the JavaScript console in Firebug or Chrome Dev Tools to see if there is an error? My guess is that the function onSucess_displaycust is undefined within the scope in which you are calling it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波