jQuery AJAX pass url as string

前端 未结 2 2001
南方客
南方客 2021-01-15 03:59

I have a ajax function that is passing a string of variables to my script but I have one variable that needs to contain a full url with parameters.

What happens is t

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-15 04:04

    Don't try to build your form data by hand. jQuery will encode it for you (with appropriate escaping) if you pass it an object.

    var url = "http://domain.com/index.php?var1=blah&var2=blah";
    
    $.ajax({
        type: "POST",
        url: "/scripts/error_check.php",
        data: { url: url, rooftop_id: rooftop_id },
        dataType: 'json'
    }); 
    

提交回复
热议问题