views:

92

answers:

1

I am trying to make an ajax call to a php script. The php script calls an rss feed using curl, gets the data, and returns the data to the funciton.

I keep getting an error

"Warning: Wrong parameter count for curl_error() in" ....

Here is my php code:1

$ch = curl_init() or die(curl_error());
        curl_setopt($ch, CURLOPT_URL, $feed);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data1 = curl_exec($ch) or die(curl_error());
        echo $data1;

and the ajax call:

$.ajax({ 
                       url: "getSingleFeed.php", 
                       type: "POST",
                       data: "feedURL=" + window.feedURL,
                       success: function(feed){

                    alert(feed);

                    }});

I tested all the variables, they are being passed correctly, I can echo them out. But this line: $data1 = curl_exec($ch) or die(curl_error());

is what is giving me the error. I am doing the same thing with curl on other pages, just without ajax, and it is working fine. Is there anything special I need to do with ajax to do this?

+5  A: 

The PHP manual states that the first parameter of curl_error is a handle returned by curl_init();. Try replacing what you pasted with what is given below. This adds the $ch variable as a parameter to all the instances of curl_error();.

$ch = curl_init() or die(curl_error($ch));
        curl_setopt($ch, CURLOPT_URL, $feed);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $data1 = curl_exec($ch) or die(curl_error($ch));
        echo $data1;
Sam152
Of course that will probably give an runtime error if curl_init fails because $ch will have the value False which is not the correct type.
Craig
same thing. Like I said, the curl script works fine just in php. It's once I call it from ajax that it doesn't work.
pfunc
Make it 'replace the curl_error() in the 4th line with curl_error($ch) and we have an answer...
Wrikken
there she goes... so, does it just handle errors differently?
pfunc
No, probably $feed is wrong, but curl will tell you as soon as you add that $ch to it's curl_error() function.
Wrikken