当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - JQUERY - get method not returning data

问题描述:

I am new to jquery and building an app using phonegap and jquery mobile.I have to load the data from a page and prepare a nested collapsible list view and present it to the user.I have written code for everything except that i don't know how to get the data from the server.

I am trying to use $.get method and in the callback of that method trying to prepare the collapsible list view from the returned server data.But the problem is this piece of code which returns the status as success but data as null

 <body>

<div data-role="page" id="pageone">

<div data-role="header">

<h1>My Commodities</h1>

</div>

<script>

$.get(" //URL to be called",function(data,status){

alert("Data: " + data + "\nStatus: " + status);

});

</script>

</div>

</body>

</html>

Image http://tinypic.com/r/fav6g1/8

网友答案:

Its returning data(see the [Object object] thing in the alert)

Your code is working fine.

Try console.log(data) instead of alert, and check the data in the console

网友答案:

The data is not null, it's in object format! Use console.log() to view what properties it has, or loop through it, or if it's JSON, parse it!

You can use Object.keys(data), console.log(data), or even (not really recommended but not necessarily bad), foreach (derp in data), or if it's JSON, use JSON.parse(data).

分享给朋友:
您可能感兴趣的文章:
随机阅读: