当从ajax返回时,我应该以json编码返回,并使用jquery.parseJSON并使用document.createElement并将数据附加到刚刚创建的Element中.
或者最好以html文本形式返回?
例,
<div id="contentcontainer"></div>
$.ajax({
type: "POST",
url: "some.php",
data: "name=John",
success: function(msg){
msgObj = jquery.parseJSON(msg);
var div = document.createElement('div');
div.style.color="red";
$(div).append(msgObj.name);
$('#contentcontainer').append(div);
}
});
//some.php
if($_POST['name']){
echo json_encode( array('name'=>$_POST['name']) );
}
Run Code Online (Sandbox Code Playgroud)
或者我应该这样做?
<div id="contentcontainer"></div>
$.ajax({
type: "POST",
url: "some.php",
data: "name=John",
success: function(msg){
$('#contentcontainer').append(msg);
}
});
//some.php
if($_POST['name']){
echo '<div style="color:red">'.$_POST['name'].'</div>';
}
Run Code Online (Sandbox Code Playgroud)
修改...抱歉我的语法不好
当然,这只是一个例子,实际情况下它会有很多数据,可能是html表格式.
当然,这仅仅是一个例子,实际情况下它会有很多数据.
如果它有很多数据,那么我需要编写很多document.createElement().并且它像写这个document.createElement('table')一样消耗时间; 使用document.createElement( 'TR');
而不是(以HTML格式返回并只是附加在容器中)
对我来说,我认为第二种格式(返回HTML)更容易.
但不确定性能是否明智,哪个更好?
请指教.
当我们通过 Eloquent 关系模型插入或更新数据时,最好使用哪种方法?
例子
$user->profile->update(['salary' => 5000]);
vs
$user->profile()->update(['salary' => 5000]);
Run Code Online (Sandbox Code Playgroud)
我明白那个
我不知何故记得我看到有人推荐使用$user->profile->update()而不是$user->profile()->update()但我找不到文章或参考链接了
但是,我发现如果$user->profile为null,那么它可能会导致错误,例如
Call to a member function update() on null
那么一直使用关系函数更新会不会更方便呢?
$user->profile()->create()
$user->profile()->update()
$user->profile()->save()
$user->profile()->delete()
Run Code Online (Sandbox Code Playgroud)
有什么情况我们应该使用$user->profile->save()来代替吗?
或者当它处于多重嵌套关系时应该使用它吗?
$user->profile->bank()->create()
$user->profile()->bank()->create()
Run Code Online (Sandbox Code Playgroud)
参考链接(出于我自己的理解)
目前,将在应用程序中使用下面的代码,两者都会触发事件
if ($user->bank === null) {
$user->bank()->save(new UserBankAccount($input)); // trigger created event
// $user->bank()->create($input);// trigger created event
} else {
$user->bank->update($input); // trigger updated event
// $user->bank()->update($input); …Run Code Online (Sandbox Code Playgroud) 如何在C#中创建像firefox"检查更新"的自动更新软件功能?因此用户无需卸载旧版本程序并重新安装最新版本.
请指教.谢谢.