jQuery AJAX pass url as string

前端 未结 2 1997
南方客
南方客 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:22

    Use encodeURIComponent() on url variable:

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

提交回复
热议问题