문제

I have a Text box and am just checking the availability of the text using jqueryAjax. Am facing a Issue like when am checking for a text containing & the Post Variables in the jquery I checked for the solution which was given in the Stack overflow Thread but still in that when we take the html encoded value for & it gives & which will again have & and as a result the jquery ajax post variable gets broken. the code i tried is given below

    //from the text field
    var textfieldValue=$('#text').val();

    //Jquery Ajax
    $.ajax({
       type: "POST",
       async: false,
       url: "ajax/CheckAvailabilityphppage.php",
       data: "fieldvalue="+textfieldValue,
       dataType: "json",
       success: function(data){
         if (data['Status'] == 'YES'){
           alert('yes its Available');
          }else{
           alert('Sorry Not Available');
          }
       }
   });

In the Firebug the Post Variables are shown as (if the text is P&P)

P   
fieldvalue P

The &P is taking as an another Post Parameter and as a result the ajax is only validating the text P

Any Help or suggestions are much Appreciated.

Thanks a Lot

도움이 되었습니까?

해결책

Pass an object to the data parameter and jquery will automagically encode it for you.

data: { fieldvalue: textfieldValue },

다른 팁

You need to URL-encode the value properly.

Use encodeURIComponent for that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top