[英]Having issues returning an XML page with ajax
I am having issues with the .ajax call: 我在使用.ajax通话时遇到问题:
$("#search").click(function()
{
$.ajax(
{
type: "GET",
url: "http://www.omdbapi.com/",
data: { s : "True", r: "XML"},
// dataType: "XML",
success:function(result)
{
$("#DBSearch").html(result);
}
});
});
S is the movie to search and r is the return type. S是要搜索的电影,r是返回类型。 When using fiddler, I can see the request coming back fine, but it is not displaying anything in my browser.
使用提琴手时,我可以看到请求返回正常,但是在浏览器中未显示任何内容。
I'm also getting a TypeError: e is null in firefox debugger. 我也收到TypeError:在firefox调试器中e为null。 Here is the html:
这是html:
<div id="DBSearch">
</div>
<button id="search">Search Movie</button>
The sample query results returns in fiddler: 示例查询结果以fiddler返回:
<root response="True">
<Movie Title="True Grit" Year="2010" imdbID="tt1403865" Type="movie"/>
<Movie Title="True Lies" Year="1994" imdbID="tt0111503" Type="movie"/>
<Movie Title="Dodgeball: A True Underdog Story" Year="2004" imdbID="tt0364725" Type="movie"/>
<Movie Title="True Romance" Year="1993" imdbID="tt0108399" Type="movie"/>
<Movie Title="True Blood" Year="2008" imdbID="tt0844441" Type="series"/>
<Movie Title="True Grit" Year="1969" imdbID="tt0065126" Type="movie"/>
<Movie Title="True Crime" Year="1999" imdbID="tt0139668" Type="movie"/>
<Movie Title="Dreamer: Inspired by a True Story" Year="2005" imdbID="tt0418647" Type="movie"/>
<Movie Title="One True Thing" Year="1998" imdbID="tt0120776" Type="movie"/>
<Movie Title="True Legend" Year="2010" imdbID="tt1425257" Type="movie"/>
</root>
Read on the api and it default returns to JSON. 在api上阅读,默认情况下返回JSON。
success:function(result)
{
var obj = eval("(" + result + ")");
$("#DBSearch").html(obj.Search[0].Title);
}
This was a much easier solution. 这是一个简单得多的解决方案。 Even better:
更好的是:
var obj = JSON.parse(result);
Thank you nzifnab and KevinB 谢谢nzifnab和KevinB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.