Jquery .get() works, but .load() does not
I've asked a similar question before -
I have an URL - https://stanfordwho.stanford.edu/SWApp/authSearch.do?search=pra**&stanfordonly=checkbox&affilfilter=everyone&filters=closed
That I'm on and I 'd like to call this - $("#StanfordProfile h2").load("https://stanfordwho.stanford.edu/SWApp/authDetail.do?key=DR647E481&search=pra**&soundex=&stanfordonly=checkbox&affilfilter=everyone&filters=closed")
The selector works when I'm on the second page, but it's not working when I try the above command. I thought this would work because I'm loading from another page on the same website (as in I shouldn't be coming across a problem due to the same-origin policy).
Now, I tried using .get(url), with a callback function that alerts the data- that shows me the correct html- does anyone know why this would happen? Also, I'd still like to use my jquery selectors to get what I want- will that be possible?
Thank You!
EDIT-
This is the html code of the page that I'm on and am trying to load from -
<div id="container_header">
<div id="topnav">
<div id="content_main">
<div id="subnav">
<div id="SWhoBody" class="stanford">
<div id="SWhoLogin">
<div id="SWhoSearch">
<div id="ResultsHead">
<div id="Toggle">
<div id="ResultsNav">
<div id="StanfordResults">
<h2>
<dl>
<dt>
<a onmouseout="swho.alone.OnMouseOut(event)" onmouseover="swho.alone.showPopup(event, 'DR647E481', 'pra**', '', 'checkbox', 'everyone', 'closed')" href="/SWApp/authDetail.do?key=DR647E481&search=pra**&soundex=&stanfordonly=checkbox&affilfilter=everyone&filters=closed">Ajay Prakash</a>
</dt>
<dd>
This is the html I'm trying to get -
<head>
<body class="stanford" onload="startstate()">
<div class="hidden">
<div id="printbanner">
<div id="container">
<div id="container_header">
<div id="topnav">
<div id="content_main">
<div id="subnav">
<div id="SWhoBody" class="stanford">
<div id="SWhoLogin">
<div id="SWhoSearch">
<div id="ResultsHead">
<div id="ProfileNav">
<div id="StanfordProfile">
<h2> Ajay Prakash </h2>
&开发者_如何学Pythonlt;div id="Contact">
<div id="HomeInfo">
<div id="Ids">
I haven't used any other javascript code as I'm working from the console
Comment thread is getting lengthy and I think I know the answer you want now:
You can specify the items you want from the second page by putting a selector after the URL:
$('#StanfordResults h2').load('https://stanfordwho.stanford.edu/SWApp/authDetail.do?key=DR647E481&search=pra**&soundex=&stanfordonly=checkbox&affilfilter=everyone&filters=closed #StanfordProfile h2');
You may need to change the first page selector (#StanfordResults h2) to match where you want the results placed.
The equivalent of this using $.get() in the case that you don't wish to insert the results directly into another location would be:
$.get('https://stanfordwho.stanford.edu/SWApp/authDetail.do?key=DR647E481&search=pra**&soundex=&stanfordonly=checkbox&affilfilter=everyone&filters=closed', function(data) {
$('#StanfordResults h2').html(data);
});
Rather than setting the .html() inside this callback, though, you could do whatever you want with 'data'. You're going to get the whole response HTML this way, though.
精彩评论