为什么这段ajax代码中的success无法进入 function initBanner(){ movie_id = getUrlParams('movie_id'); cinema_id = getUrlParams('cinema_id'); var cinemaBriefContainer = $(".cinema-brief-container"); var avatarShadow = $(".avatar-shadow"); $.ajax({ type:'post', url: "/schedule/findScheduleByCinemaAndMovie", dataType:'json', data: { movie_id: movie_id, cinema_id: cinema_id }, success:function (obj) { console.log("11111111111"+obj); cinemaBriefContainer.prepend( "<h3 class=\"name text-ellipsis\">" + obj.data[0].schedule_hall.hall_cinema.cinema_name + "</h3>" + "<div class=\"address text-ellipsis\">" + obj.data[0].schedule_hall.hall_cinema.cinema_address + "</div>" ); avatarShadow.append( "< img class=\"avatar\" src=\"../static/images/cinemas/" + obj.data[0].schedule_hall.hall_cinema.cinema_name + ".jpg\">" + "<div class=\"avatar-num\">查看全部21张图片</div>" ); initMoive(obj); //初始化电影信息 initSchedule(obj); //初始化场次信息 }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); }, }); }
时间: 2024-02-14 11:31:43 浏览: 30
有几种可能导致你的ajax代码中的success无法进入:
1. 请求的URL不正确:请确保URL "/schedule/findScheduleByCinemaAndMovie" 是正确的,并且能够返回正确的数据。
2. 请求的数据格式不正确:请确保你在发送请求时指定了正确的dataType为'json',并且服务器返回的数据也是合法的JSON格式。
3. 请求参数不正确:请确保你发送的数据参数movie_id和cinema_id是正确的,并且服务器能够根据这些参数返回对应的数据。
4. 服务器返回错误:如果服务器返回了错误的状态码,比如404或500,那么可能是服务器端出现了问题。你可以在error回调函数中输出XMLHttpRequest.status来查看具体的错误码。
请检查以上几个方面,看是否有任何问题导致success无法进入。如果问题仍然存在,请提供更多的信息以便我能够帮助你更好地解决问题。
相关问题
这是我的一个基于ssm框架的maven项目中jsp页面的代码,我想知道当我把这段代码function initBanner(){ movie_id = getUrlParams('movie_id'); cinema_id = getUrlParams('cinema_id'); var cinemaBriefContainer = $(".cinema-brief-container"); var avatarShadow = $(".avatar-shadow"); $.ajax({ type:'post', url: "/schedule/findScheduleByCinemaAndMovie", dataType:'json', data: { movie_id: movie_id, cinema_id: cinema_id }, success:function (obj) { console.log("11111111111"+obj); cinemaBriefContainer.prepend( "<h3 class=\"name text-ellipsis\">" + obj.data[0].schedule_hall.hall_cinema.cinema_name + "</h3>" + "<div class=\"address text-ellipsis\">" + obj.data[0].schedule_hall.hall_cinema.cinema_address + "</div>" ); avatarShadow.append( "<img class=\"avatar\" src=\"../static/images/cinemas/" + obj.data[0].schedule_hall.hall_cinema.cinema_name + ".jpg\">" + "<div class=\"avatar-num\">查看全部21张图片</div>" ); initMoive(obj); //初始化电影信息 initSchedule(obj); //初始化场次信息 } }); } 跟我controller里这段代码关联起来之后,为什么无法使用System.out.println(list);打印出list集合中的内容,以及我该如何改动
在JSP页面中的JavaScript代码无法直接使用Java的System.out.println()方法进行输出,因为JSP页面和Java代码是在不同的环境中执行的。如果你想在控制台输出list集合中的内容,你可以将list对象转换为JSON字符串,并通过console.log()方法打印出来。以下是修改后的代码示例:
```java
// 修改Controller中的代码
import com.alibaba.fastjson.JSON;
@Controller
@RequestMapping("/schedule")
public class ScheduleController {
@Autowired
private ScheduleService scheduleService;
@RequestMapping("/findScheduleByCinemaAndMovie")
@ResponseBody
public String findScheduleByCinemaAndMovie(@RequestParam("movie_id") Integer movieId, @RequestParam("cinema_id") Integer cinemaId) {
List<Schedule> list = scheduleService.findScheduleByCinemaAndMovie(movieId, cinemaId);
String listJson = JSON.toJSONString(list);
System.out.println(listJson); // 输出list的JSON字符串到控制台
return listJson;
}
}
```
在上述代码中,使用了FastJSON库将list对象转换为JSON字符串,并通过System.out.println()方法输出到控制台。
另外,你也可以在前端页面的JavaScript代码中使用console.log()方法输出返回的JSON数据,以便查看内容:
```javascript
success: function (obj) {
console.log(obj); // 输出返回的JSON数据到控制台
// 其他代码...
}
```
这样你就可以在浏览器的开发者工具控制台中查看到返回的JSON数据了。
android studio实现图片轮播的代码
您可以通过使用ViewPager和PagerAdapter实现图片轮播的功能,以下是实现图片轮播的示例代码:
1. 在您的布局XML文件中,添加一个ViewPager和一个指示器:
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/transparent"
app:tabGravity="center"
app:tabIndicatorColor="@color/colorPrimary"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabTextColor="@color/white"/>
2. 在您的Activity或Fragment中,设置ViewPager和PagerAdapter:
private fun initBanner() {
val adapter = BannerAdapter(this, images)
viewPager.adapter = adapter
tabLayout.setupWithViewPager(viewPager, true)
// 自动滚动
Timer().schedule(object : TimerTask() {
override fun run() {
runOnUiThread {
if (currentIndex == images.size - 1) {
currentIndex = 0
} else {
currentIndex++
}
viewPager.currentItem = currentIndex
}
}
}, 3000, 3000)
}
class BannerAdapter(private val ctx: Context, private val images: ArrayList<String>) : PagerAdapter() {
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val imageView = ImageView(ctx)
imageView.scaleType = ImageView.ScaleType.CENTER_CROP
Glide.with(ctx).load(images[position])
.into(object : SimpleTarget<Drawable>() {
override fun onResourceReady(
resource: Drawable,
transition: Transition<in Drawable>?
) {
imageView.setImageDrawable(resource)
container.addView(imageView)
}
})
return imageView
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
container.removeView(`object` as View)
}
override fun getCount() = images.size
override fun isViewFromObject(view: View, `object`: Any) = view == `object`
}
这段代码中,我们使用Glide来加载图片,设置一个定时器来自动滚动图片,并且在setupWithViewPager()中设置了一个指示器。当然,您可以根据自己的需求来修改代码。
希望这段代码能够对您有所帮助!
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)