开发者

How to choose what to display in a ajax request?

开发者 https://www.devze.com 2023-01-05 05:18 出处:网络
What if I request the URL htt开发者_运维问答p://www.google.com via AJAX, for example and in the on successfunction I just wanted to display the I\'m feeling lucky button in some div?

What if I request the URL htt开发者_运维问答p://www.google.com via AJAX, for example and in the on successfunction I just wanted to display the I'm feeling lucky button in some div?

For example

$.ajax({
    url: 'www.google.com',
    success: function(html) {
        $('div').html(html);
    }
});

this is for displaying the whole page, but I want only to display the button. How do I do that?


$.ajax({ 
    url: 'www.google.com', 
    success: function(html) { 
        $('div').html($(html).find('input[name=btnI]')); 
    } 
});

You can replace input[name=btnI] with your own condition.


You could put a div around the button like:

<div id='button'><button>blah</button</div>

and the Ajax URL would be something like:

url: 'www.google.com #button',

Just add the selector to the end of the URL and it will return only that content.

0

精彩评论

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