Jquery

使用Ajax

Jquery 封装了操作Ajax的函数。 有三个函数是常用的: get, post 和 ajax。 ajax可以设置更多的参数,比另外2个好用。
由于Ajax调用的网址是外部的,所以函数执行有同步和异步之分别。异步执行时,函数立即返回。我不知道在异步模式下是否有消息通知的机制,目前还没有找到,如果有的话更新。
use as this:

    $.get(url,function(data){
        jsonObj = JSON.parse(data);
        $("#txtStatus").text(
                "DB connected. There is(are) "
                + jsonObj.Count
                + " record(s)." );
        $(":input[name='prodList']").val(jsonObj.Products);
        alert("Data Loaded: " + jsonObj);
    });

If you want to use synchronous mode with Ajax, use as this:

    $.ajax({
        async:          false,
        type:           "POST",
        url:            url,
        contenttype:    "application/json",
        datatype:       "json",
        data:           jsonObj,
        success:        function(jsonResult) {
            $("#txtPrice").text(jsonResult);
        }
    });

Jquery的Selector

$("#txtStatus").text( "DB connected. Record count: " );

$(":input[name='btn-price']").click(function () {
                    var pname = $(":input#txtProd").val();

                    var url = "test1-hint.php?r=2&p=" + pname;

                    $.ajax({
                        async:          false,
                        type:           "POST",
                        url:            url,
                        contenttype:    "application/json",
                        datatype:       "json",
                        data:           jsonObj,
                        success:        function(jsonResult) {
                            $("#txtPrice").text(jsonResult);
                        }
                    });
                });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值