0

i am making a product add page for e commerce and after the data is being submitted then a ajax call pass all the data to the query page and it stores the info to the database. but the problem is when a large amount of html data is being passed then it dosent pass anything in the description . suppose write a short paragraph in description area then it pass throught ajax easily . but whenever there is long paragraphs or lets a very large amount of html data. it fails . the code i am using is

function product()
{
var micategory=$('.micatg option:selected').val();
var misubcategory=$('.misubcatg option:selected').val();
var currency=$('.micurrency option:selected').val();
var looking_for=$('input:radio[name=lookingfor]:checked').val();
var title=$('.btitle').val();
var condition=$('input:radio[name=bcondition]:checked').val();
var buy_description=CKEDITOR.instances['textarea_description_add'].getData();

var buy_country=$('.bcountry option:selected').text();
var buy_city=$('.bcity').val();
var zipcode=$(".bzipcode").val();
var price=$(".bprice").val();
var video_link=$("#infolink").val();
var address=$(".baddress").val();
var loguser=$("#loginuser").val();
var product_id=$("#prod_id").val();
var dataString = 'category='+ micategory+'&subcategory='+misubcategory+'&currency='+currency+'&looking_for='+looking_for+'&title='+title+'&condition='+condition+'&country='+buy_country+'&city='+buy_city+'&zipcode='+zipcode+'&price='+price+'&video_link='+video_link+'&address='+address+'&loguser='+loguser+'&product_id='+product_id+'&description='+encodeURIComponent(buy_description);
alert(dataString);

$.ajax({
type: "GET",
url: "modules/buy&sell/add_prod.php",
data: dataString,
cache: false,
success: function(html){
alert(html);
alert("Your Product is Successfully Added");
window.location = "buy.php";
 }
 });
}

in this due to large amount of html i used encodeURIComponent reading somewhere in stack. but still no help with this. can anyone help me with this.

Param Veer
  • 776
  • 4
  • 13
  • 27

3 Answers3

2

Use POST instead of GET, Because of size limitation of GET.

within ajax config object.

So, it will look like:

$.ajax({
    type: "POST",
    url: "modules/buy&sell/add_prod.php",
    data: dataString,
    cache: false,
    dataType: 'html', // add this if you only passed html, if have other value then remove it
    success: function(html) {
        alert(html);
        alert("Your Product is Successfully Added");
        window.location = "buy.php";
    }
});
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
2

I think this is due to the limit on the data size when passing data with the GET method.

More details here.

You should use the POST method instead.

Community
  • 1
  • 1
maxdec
  • 5,707
  • 2
  • 30
  • 35
0

You should use post method ,

type: "Post",

With Get method we can send limited data. It depends on browser.

nitin jain
  • 298
  • 6
  • 19