当我刷新文档时,有时工作正常(我在控制台中获取json对象),但很多时候我得到500(内部服务器错误)并且从jQuery我看到错误是:xhr.send(options.hasContent) && options.data || null);请帮我。这是代码:
package com.superiordevs.ab.listviewclickcontrol;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.app.Activity;
public class SecondActivity extends Activity {
ListView list;
String[] web = {
"Google Plus",
"Twitter",
"Windows",
"Bing",
"Itunes",
"Wordpress",
"Drupal",
"Bhutan",
"pakistan",
"Romania",
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_activity);
CustomList2 adapter = new CustomList2(SecondActivity.this,web);
list=(ListView)findViewById(R.id.LVtwo);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String itemText = web[position];
Toast.makeText(SecondActivity.this, itemText, Toast.LENGTH_LONG).show();
}
});
}
}
'/ ajax / cis'是一个仅返回json对象的laravel控制器:
$(document).ready(function(){
$.ajax({
url: '/ajax/cis',
method: "GET",
success: function(data){
console.log(data);
}
});
});
我也试过post方法:
return response()->json(['cis_names'=>'cis_names']);
答案 0 :(得分:0)
尝试使用Blade并查看是否有效:
$.ajax({
url: '/ajax/cis',
method: "POST",
data:{_token: '{{csrf_token()}}'},
success: function(data){
console.log(data);
}
});