Arun Arun
Arun Arun

Reputation: 9

Ajax doesnot take string or values with special characters

in my form i want to FETCH item description using item code for example i have item description as 24"STUB END 316L SCH10S and its item code is STUB316LS10SW so when i search in item code field using STUB316LS10SW the item description for that specific item code is not fetching because in item description i have 24" ie special characters so the ajax is not fetching item description ..can you please help on this

         $(function() {
         function log( message ) {
         $( "<div>" ).text( message ).prependTo( "#log" );
          $( "#log" ).scrollTop( 0 );
         }
        $("#itemcode1").autocomplete({
         source: function( request, response ) {
        $.ajax({
        url: "getProductList.php",
        dataType: "json",
     data: {
      name_startsWith: request.term
      },
     success: function( data ) {
      response($.map( data.geonames, function( item ) {


      return {
      label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") ,
     value: item.nameval,
     value1: item.toponymName,
     price:item.price,
     quantity:item.quantity,
     prodId:item.prodId,
      itemcode:item.itemcode,
    }
    }));
   }
   });
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="style1">
          <tr>
            <td>Item Code </td>
            <td>&nbsp;</td>
            <td><input  type="text" id="itemcode1" name="itemcode1"  /></td>
          </tr>
          <tr>
        <td width="125">Products/Description</td>
        <td width="10">:</td>
        <td width="175"><input name="productDesc1" type="text"  id="productDesc1"></td>
      </tr>
         <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>
        <input type="submit" name="submit" value="Create" 
        style="width:100px;" id="crt"></td>
      </tr>

Upvotes: 0

Views: 268

Answers (2)

Prafulla
Prafulla

Reputation: 590

use this and encode your description this will accept ur special character..you may searching for this not sure what actually you want

encodeURIComponent()

or

string rawurlencode ( string $str )

improve your question... it's difficult to understand

Upvotes: 0

dr.dimitru
dr.dimitru

Reputation: 2702

Wrap values (or everything) with special characters into encodeURI() function: http://www.w3schools.com/jsref/jsref_encodeuri.asp

To decode in JS use: decodeURI() function: http://www.w3schools.com/jsref/jsref_decodeuri.asp

To decode in PHP use rawurldecode() function: http://www.php.net/manual/en/function.rawurldecode.php

Upvotes: 1

Related Questions