2013-11-27 51 views
-1

我有一个jquery后这样字符串返回的数据

jQuery.post("script_myrequisition.php", {"user_empno":user_no}, function(data) { 

    jQuery('#type2').html(data); 
    var pageHtml =jQuery (data); 


if(substr(pageHtml,0,2)=='No'){ jQuery('#cancel').hide();} 
else{  jQuery('#cancel').show();} 
}); 

下面的HTML我有这样的邮寄方法返回

<input id='cancel' name='cancel' type='Submit' value='Cancel Selected' /> 

数据包含要么“没有找到记录”或“总记录数= x,后面是表格形式的记录“。

这不起作用。取消按钮不显示。请帮助

+2

你为什么这样做'pageHtml =的jQuery(数据);' –

+0

试'jQuery.post( “script_myrequisition.php”,{ “user_empno”:user_no },功能(数据){ jQuery的( '#2型')的html(数据); 变种pageHtml =。 jQuery(data); if(data.substring(0,2)=='No'){ jQuery('#cancel')。hide(); } else { jQuery('#cancel')。show(); } });' –

+0

我简单地使用了数据。它不起作用。在这两种情况下,javascript错误说对象需要 – mansoondreamz

回答

0

它看起来像data是一个字符串,所以没有必要为它创建一个jQuery包装对象,只是用它来获得子

jQuery.post("script_myrequisition.php", { 
    "user_empno": user_no 
}, function (data) { 
    jQuery('#type2').html(data); 

    jQuery('#cancel').toggle(data.substring(0, 2) == 'No'); 
    // you can use toggle 
    //if (data.substring(0, 2) == 'No') { 
    // jQuery('#cancel').hide(); 
    //} else { 
    // jQuery('#cancel').show(); 
    //} 
});