我正在使用ajax,但它的行为不同。我只想知道我应该 在里面 模型 ,请 查看 我是说, 控制器 是的。
这个while包含两个操作:插入和从数据库中获取数据。
![In image their is subject and textarea as input.When i click submit the input dispaly in comment which is just above the Subject input ] 1
查看
<form action="" method="POST"> <input type="hidden" name="myId" id="myId" value="" /> <div class="form-group px-4"> <label for="subject">Subject</label> <input type="text" id="js_subject" name="js_subject"> </div> <div class="form-group px-4"> <label for="exampleFormControlTextarea1">Example textarea</label> <textarea class="form-control" name = "js_text" id="js_text" rows="3"></textarea> </div> <input type="submit" id="comment-info" value="submit" name="submit" class="btn btn-primary"> </form>
使用jquery ajax请求,在somepage.php上使用if和else进行插入、选择和 回显一些消息给两者和die();
$('form').on('submit', function(event){ event.preventDefault(); $.ajax({ type:'post', url:'somepage.php', data:$(this).serialize(), success:function(data){ var tmp = data; if(data = "message1"){ //do whatever }else if(data = "message2"){ //do whatever } }) });