dsk49208 2011-08-17 00:40
浏览 14
已采纳

获取信息时弹出警报

How can i display an alert message or alert box when getting the information(not submitting)

i have few form structures(text type) in my html when i enter the id in one of the form and press get button all the other forms will be filled based on the form submitted.

for the above i am using json and jquery

Ex:

Jquery

$(document).ready(function(){
$("#button1").click(function(){
$.post('script_1.php', { id: $('input[name="id"]', '#myForm').val() },
function(json) { 
$("input[name='title']").val(json.title);
$("input[name='name']").val(json.name); 
$("input[name='age']").val(json.age);
$("#institution").val(json.institution); 
}, "json");
 });

json:

 $abc_output = array('title' => $row['title'],'name' => $row['name'],'age' => $row['age'], 'institution' => $row['institution']);
 echo json_encode($abc_output);

now the problem is all the id's will not be having information so when the user enters some id with no information pop up or alert box need to be submitted saying no id.

How can i do that?

Note: as it is get info the result will be displayed on the same page, if its submit i could have echoed id not found in DB in the server side php(script_1.php) which is not the case here.

Html:

 id: <input type="text" name="id"/>
 <div id="hidden" style="display: none;">
 <p>Title:<input type="text" name="title"/></p>
 <p>name:<input type="text" name="rno"/></p>
 <p>age:<input type="text" name="age"/></p>
  Institution: <select id="institution" name="institution">
  <option value="None">-- Select --</option>
  <option value="ab">ab</option>
   <option value="bc">bc</option> 
   </select>

  </div>
  <br/> 
 <input type="button" id="button1" value ="Get Info" onclick="document.getElementById('hidden').style.display = '';"/> 

 </form>
 <div id="age"></div>
 </body>
 </html>
  • 写回答

2条回答 默认 最新

  • duanji9264 2011-08-17 02:19
    关注

    It may be helpful to set up an AJAX error handler, to handle things like session timeouts, json 'parseerror', etc.

    $(document).ajaxError(function() {
     alert( "Triggered ajaxError handler." );
    });
    

    This can help you to determine if the problem is with the success callback not being called.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址