我想让我的消息线程进入我的模态。单击模式按钮后,我无法获得具有相同参考编号的所有消息。我的代码在接收到传递给控制器的refNumber之前首先执行查询。请帮我解决这个问题。 这些是我的代码。
这是我的控制器(HomeController)
ProcessStartInfo sigCheckProcess = new ProcessStartInfo();
sigCheckProcess.FileName = "\\sigcheck64.exe";
sigCheckProcess.Arguments = "-a -h -i -l -s " ;
sigCheckProcess.RedirectStandardOutput = true;
sigCheckProcess.UseShellExecute = false;
sigCheckProcess.CreateNoWindow = true;
using (Process exeProcess = Process.Start(sigCheckProcess))
{
exeProcess.WaitForExit();
string line;
using (System.IO.StreamWriter writer = new System.IO.StreamWriter("output.txt")) // output txt file.
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(Path.Combine(@"c:\temp\", "test.txt"))) // replaces sigCheckProcess.StandardOutput
{
while (!reader.EndOfStream)
{
line = reader.ReadLine();
writer.WriteLine(line);
}
}
}
}
这是我的javascript函数
public function getAllMessage(Request $request){
$refNumber = $request->get('refNumber');
$messageThread = DB::TABLE('i_di_thread')
->SELECT('message')
->WHERE('refNumber', $refNumber);
return view ('showInquiries', ['messageThread'=>$messageThread]);
}
这是我的刀刃
$('#inquire_t tbody').on('click','#mensahe',function(){
var refNumber = $(this).attr('value');
getMessageThread(refNumber);
function getMessageThread(refNumber){
$.ajax({
url: 'getMessageThread',
type: 'GET',
headers: {'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')},
data: 'refNumber='+refNumber,
dataType: 'text',
success:function(msg){
}//each
});
}
答案 0 :(得分:2)
DB::TABLE('i_di_thread')
->SELECT('message')
->WHERE('refNumber', $refNumber);
将返回Illuminate/Database/Eloquent/Builder
实例。 Check here
添加->get()
以作为“选择”语句执行查询。 Check here
完整代码:
public function getAllMessage(Request $request){
$refNumber = $request->get('refNumber');
$messageThread = DB::table('i_di_thread')
->select('message')
->where('refNumber', $refNumber)
->get();
return view ('showInquiries', ['messageThread'=>$messageThread]);
}
已更新
您正在使用刀片显示数据,而不是异步显示。
Check this answer if you want to dynamically get data and to display in modal.
注意: 使用optional函数访问属性而不会引起错误。
示例:
<div class="row" style=" margin-left: 30px; margin-bottom: 5px; left: 20px; width: 550px; height: 200px; overflow: auto;">
<div>
@foreach ($messageThread as $thread)
{{optional($thread)->message}} {{-- accessing property without causing error --}}
<br>
@endforeach
</div>
<br>
</div>
答案 1 :(得分:0)
您应该尝试以下操作:
public function getAllMessage(Request $request){
$refNumber = $request->get('refNumber');
$messageThread = DB::TABLE('i_di_thread')
->SELECT('message')
->WHERE('refNumber', $refNumber)->get();
return view ('showInquiries', ['messageThread'=>$messageThread]);
}