开发者

Jquery: Only fill in data from .load if there is content?

开发者 https://www.devze.com 2023-03-17 12:20 出处:网络
Im using the jquery .load function to query a php file that will output some data.Now sometimes the script will return nothing.In this case, can I have the load function not put any d开发者_高级运维at

Im using the jquery .load function to query a php file that will output some data. Now sometimes the script will return nothing. In this case, can I have the load function not put any d开发者_高级运维ata into my specified div? (right now it clears out the div and just puts a blank white area.

Thanks!


try using $.get;

$.get('<url>',{param1:true},function(result){
    if(result) {
        $('selector').html(result);
    }
    else {
        //code to handle if no results
    }       
});


Use $.get http://api.jquery.com/jQuery.get/


in addition to @jerjer's post, you can also use this:

var paramData= 'param=' + param1 + '&user=<?echo $user;?>';

$.ajax({
    type: "GET",
    data:paramData,
    url: "myUrl.php",
    dataType: "json", // this line is optional
    success: function(result) {
        // do you code here
        alert(result); // this can be an any value returned from myUrl.php
    },
    statusCode: {
        404: function() {
            alert('page not found');
        }
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消